Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
test-platform
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
马博
test-platform
Commits
af48a38c
Commit
af48a38c
authored
Oct 30, 2018
by
赵然
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zr
parent
99daacb5
Changes
26
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
2483 additions
and
20 deletions
+2483
-20
优惠券测试_DuibaTest.java
...test/java/http/cases/NewActivityTest/优惠券测试_DuibaTest.java
+128
-0
全局红包账户_DuibaTest.java
...est/java/http/cases/NewActivityTest/全局红包账户_DuibaTest.java
+70
-0
出奖订单测试_DuibaTest.java
...est/java/http/cases/NewActivityTest/出奖订单测试_DuibaTest.java
+212
-0
多奖项中奖限制_DuibaTest.java
...st/java/http/cases/NewActivityTest/多奖项中奖限制_DuibaTest.java
+166
-0
奖品发放限制_DuibaTest.java
...est/java/http/cases/NewActivityTest/奖品发放限制_DuibaTest.java
+168
-0
定向测试_DuibaTest.java
src/test/java/http/cases/NewActivityTest/定向测试_DuibaTest.java
+131
-0
扣库存测试_DuibaTest.java
...test/java/http/cases/NewActivityTest/扣库存测试_DuibaTest.java
+321
-0
抽奖异常测试_DuibaTest.java
...est/java/http/cases/NewActivityTest/抽奖异常测试_DuibaTest.java
+317
-0
推荐位测试_DuibaTest.java
...test/java/http/cases/NewActivityTest/推荐位测试_DuibaTest.java
+138
-0
新活动工具测试_DuibaTest.java
...st/java/http/cases/NewActivityTest/新活动工具测试_DuibaTest.java
+165
-0
无积分测试_DuibaTest.java
...test/java/http/cases/NewActivityTest/无积分测试_DuibaTest.java
+119
-0
谢谢参与测试_DuibaTest.java
...est/java/http/cases/NewActivityTest/谢谢参与测试_DuibaTest.java
+64
-0
闯关活动测试_DuibaTest.java
...est/java/http/cases/NewActivityTest/闯关活动测试_DuibaTest.java
+77
-0
页面元素测试_DuibaTest.java
...est/java/http/cases/NewActivityTest/页面元素测试_DuibaTest.java
+91
-0
领奖流程测试_DuibaTest.java
...est/java/http/cases/NewActivityTest/领奖流程测试_DuibaTest.java
+166
-0
ConfirmService.java
src/test/java/http/service/app/ConfirmService.java
+2
-2
CouponExchangeService.java
src/test/java/http/service/app/CouponExchangeService.java
+2
-2
SeckillService.java
src/test/java/http/service/app/SeckillService.java
+3
-3
VirtualExchangeService.java
src/test/java/http/service/app/VirtualExchangeService.java
+1
-1
CustomHdToolCtrlService.java
src/test/java/http/service/hd/CustomHdToolCtrlService.java
+4
-4
DevFloorService.java
src/test/java/http/service/hd/DevFloorService.java
+2
-2
DevItemService.java
src/test/java/http/service/hd/DevItemService.java
+1
-1
DevSkinService.java
src/test/java/http/service/hd/DevSkinService.java
+1
-1
DeveloperService.java
src/test/java/http/service/hd/DeveloperService.java
+2
-2
DsOrderService.java
src/test/java/http/service/hd/DsOrderService.java
+2
-2
ExcelDataProvider.java
src/test/java/utils/ExcelDataProvider.java
+130
-0
No files found.
src/test/java/http/cases/NewActivityTest/优惠券测试_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
base.Config
;
import
http.service.Activity.ManagerService
;
import
http.service.Activity.NewActivityService
;
import
utils.MatcherString
;
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 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
();
@DataProvider
public
Iterator
<
Object
[]>
providerMethod
(
Method
method
)
throws
IOException
{
Iterator
<
Object
[]>
result
=
null
;
if
(
method
.
getName
().
equals
(
"优惠券测试"
))
{
result
=
new
ExcelDataProvider
(
"duiba/活动优惠券"
);
}
return
result
;
}
@Test
(
dataProvider
=
"providerMethod"
)
public
void
优惠券测试
(
Map
<
String
,
String
>
data
)
throws
Exception
{
Thread
.
sleep
(
2000
);
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
);
//获取管理员后台优惠券库存
String
remind
=
MatcherString
.
getString
(
LinkResponse
.
asString
(),
"option remain=\"(.*?)\""
,
1
);
logger
.
info
(
"抽奖前当前库存:"
+
remind
);
//扣去1库存
remind
=
String
.
valueOf
(
Integer
.
valueOf
(
remind
)-
1
);
//进行接口测试传参
Response
response
=
this
.
新活动工具接口传参
(
data
.
get
(
"activityId"
),
data
.
get
(
"token"
),
data
.
get
(
"device"
));
// response.prettyPrint();
//根据case选择对应的校验项
int
casenum
=
Integer
.
parseInt
(
data
.
get
(
"casenum"
));
switch
(
casenum
){
case
1
:
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.iosDownloadUrl"
),
linkUrl
,
"校验Url失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.useBtnText"
),
actusebtn
,
"校验useBtnText失败"
);
logger
.
info
(
"校验链接券码项:openUrl,useBtnText成功"
);
break
;
case
2
:
if
(
data
.
get
(
"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"
),
actusebtn
,
"校验useBtnText失败"
);
logger
.
info
(
"校验商家落地项:openUrl,useBtnText成功"
);
break
;
case
3
:
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.iosDownloadUrl"
).
contains
(
actLinkEx
),
"兑换记录页url与实际url不匹配"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.useBtnText"
),
"查看使用方法"
,
"校验useBtnText失败"
);
logger
.
info
(
"校验兑换记录项:openUrl,useBtnText成功"
);
break
;
}
//通用校验项
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.title"
),
acttitle
,
"校验title失败"
);
logger
.
info
(
"校验通用项:title成功"
);
//获取管理员后台优惠券库存
Thread
.
sleep
(
5000
);
Response
LinkResponse2
=
managerService
.
ShowCoupons
(
data
.
get
(
"couponId"
));
String
Newremind
=
MatcherString
.
getString
(
LinkResponse2
.
asString
(),
"option remain=\"(.*?)\""
,
1
);
logger
.
info
(
"抽奖后当前库存:"
+
Newremind
);
//校验比较,抽奖前后优惠券库存
Assert
.
assertEquals
(
Newremind
,
remind
);
logger
.
info
(
"校验抽奖前后库存正确"
);
}
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
=
30
;
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
src/test/java/http/cases/NewActivityTest/全局红包账户_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
base.DuibaTestBase
;
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.testng.Assert
;
import
org.testng.annotations.Test
;
import
java.util.Map
;
/**
* Created by zhaoran on 2018/9/21
*/
public
class
全局红包账户
_DuibaTest
extends
DuibaTestBase
{
@Autowired
NewActivityService
newActivityService
;
@Autowired
ManagerService
managerService
;
private
static
DuibaLog
logger
=
DuibaLog
.
getLogger
();
@Test
public
void
全局红包测试
()
throws
Exception
{
Map
<
String
,
Object
>
selectResult
=
jdbc
.
findSimpleResult
(
"select * from consumer_accounts.tb_consumer_account_0687 where account_id = '100025007_0_0' "
);
int
balance
=
Integer
.
parseInt
(
String
.
valueOf
(
selectResult
.
get
(
"balance_amount"
)));
logger
.
info
(
"账户原有余额为"
+
balance
);
//进行接口测试传参
Response
response
=
this
.
新活动工具接口传参
(
"32696"
,
"7ywbta5"
,
"iOS"
);
// response.prettyPrint();
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.bonusMax"
),
"50"
,
"校验红包最大值失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.bonusMin"
),
"10"
,
"校验红包最小值失败"
);
int
bonus
=
Integer
.
parseInt
(
response
.
jsonPath
().
getString
(
"lottery.bonus"
));
logger
.
info
(
"中奖金额为"
+
bonus
);
balance
=
balance
+
bonus
;
logger
.
info
(
"预期余额为"
+
balance
);
selectResult
=
jdbc
.
findSimpleResult
(
"select * from consumer_accounts.tb_consumer_account_0687 where account_id = '100025007_0_0' "
);
int
balanceNew
=
Integer
.
parseInt
(
String
.
valueOf
(
selectResult
.
get
(
"balance_amount"
)));
logger
.
info
(
"实际余额为"
+
balanceNew
);
Assert
.
assertEquals
(
balanceNew
,
balance
,
"全局红包增加账户余额失败"
);
}
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
=
30
;
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
src/test/java/http/cases/NewActivityTest/出奖订单测试_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
base.Config
;
import
base.DuibaTestBase
;
import
http.service.Activity.ManagerService
;
import
http.service.Activity.NewActivityService
;
import
utils.MatcherString
;
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.Test
;
import
java.util.Map
;
/**
* @author zhaoran
* @create 2018/1/2
* @since 1.0.0
*/
@ContextConfiguration
(
classes
=
Config
.
class
)
public
class
出奖订单测试
_DuibaTest
extends
DuibaTestBase
{
@Autowired
NewActivityService
newActivityService
;
@Autowired
ManagerService
managerService
;
private
static
DuibaLog
logger
=
DuibaLog
.
getLogger
();
@Test
(
description
=
"开发者虚拟商品接口设置为不通状态,充值不会成功"
)
public
void
出奖虚拟订单校验
()
throws
Exception
{
//获取库存
String
remind
=
this
.
getremind_db
(
"27508"
);
//扣去1库存
remind
=
String
.
valueOf
(
Integer
.
valueOf
(
remind
)-
1
);
//进行接口测试传参
Response
response
=
newActivityService
.
doJoin2
(
"21079"
,
"asdasd"
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
response
=
newActivityService
.
getOrderStatus2
(
orderId
,
"iOS"
);
response
.
prettyPrint
();
String
result
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"result"
));
int
i
=
30
;
while
(
i
>
0
&&(
result
.
equals
(
"0"
))){
Thread
.
sleep
(
1000
);
response
=
newActivityService
.
getOrderStatus2
(
orderId
,
"iOS"
);
result
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"result"
));
i
--;
response
.
prettyPrint
();
}
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.link"
).
contains
(
"/activity/takePrizeNew?"
),
"校验link失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.type"
),
"virtual"
,
"校验useBtnText失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验success失败"
);
logger
.
info
(
"校验链接券码项:link,type,success"
);
Thread
.
sleep
(
2000
);
Map
<
String
,
Object
>
selectResult
=
jdbc
.
findSimpleResult
(
"select * from credits_hdtool.hdtool_orders_0687 where id = '"
+
orderId
+
"'"
);
logger
.
info
(
"主订单为:"
+
selectResult
.
get
(
"main_order_num"
));
String
main_orderId
=
String
.
valueOf
(
selectResult
.
get
(
"main_order_num"
));
Map
<
String
,
Object
>
selectResult2
=
jdbc
.
findSimpleResult
(
"select * from orders_consumer.orders_0687 where order_num = '"
+
main_orderId
+
"' "
);
//logger.info("selectResult结果为:"+selectResult);
Assert
.
assertEquals
(
selectResult2
.
get
(
"biz_params"
),
"DUIBA_TEST"
,
"虚拟商品出奖标识DUIBA_TEST校验失败"
);
logger
.
info
(
"数据库存储虚拟商品标记结果为:"
+
selectResult2
.
get
(
"biz_params"
));
String
flowWork
=
String
.
valueOf
(
selectResult2
.
get
(
"flowwork_stage"
));
int
j
=
10
;
while
(
j
>
0
&&
!
flowWork
.
equals
(
"Success-complete"
))
{
Thread
.
sleep
(
1000
);
selectResult2
=
jdbc
.
findSimpleResult
(
"select * from orders_consumer.orders_0687 where order_num = '"
+
main_orderId
+
"' "
);
flowWork
=
String
.
valueOf
(
selectResult2
.
get
(
"flowwork_stage"
));
logger
.
info
(
"数据库订单节点:"
+
flowWork
);
j
--;
}
// Assert.assertEquals(selectResult2.get("error4developer"),"上游充值异常","报错信息校验失败");
Assert
.
assertEquals
(
flowWork
,
"Success-complete"
,
"数据库主订单流程节点校验失败"
);
//校验库存
String
Newremind
=
this
.
getremind_db
(
"27508"
);
Assert
.
assertEquals
(
Newremind
,
remind
);
logger
.
info
(
"校验抽奖前后库存正确"
);
}
@Test
public
void
出奖优惠券订单校验
()
throws
Exception
{
Response
response
=
newActivityService
.
doJoin2
(
"31711"
,
"asdasd"
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
response
=
newActivityService
.
getOrderStatus2
(
orderId
,
"iOS"
);
response
.
prettyPrint
();
String
result
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"result"
));
int
i
=
30
;
while
(
i
>
0
&&(
result
.
equals
(
"0"
))){
Thread
.
sleep
(
1000
);
response
=
newActivityService
.
getOrderStatus2
(
orderId
,
"iOS"
);
result
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"result"
));
i
--;
response
.
prettyPrint
();
}
Map
<
String
,
Object
>
selectResult
=
jdbc
.
findSimpleResult
(
"select * from credits_hdtool.hdtool_orders_0687 where id = '"
+
orderId
+
"' "
,
null
);
logger
.
info
(
"主订单为:"
+
selectResult
.
get
(
"main_order_num"
));
String
main_orderId
=
String
.
valueOf
(
selectResult
.
get
(
"main_order_num"
));
Map
<
String
,
Object
>
selectResult2
=
jdbc
.
findSimpleResult
(
"select * from orders_consumer.orders_0687 where order_num = '"
+
main_orderId
+
"' "
);
logger
.
info
(
"数据库订单节点:"
+
selectResult2
.
get
(
"flowwork_stage"
));
String
flowWork
=
String
.
valueOf
(
selectResult2
.
get
(
"flowwork_stage"
));
int
j
=
10
;
while
(
j
>
0
&&
!
flowWork
.
equals
(
"Success-complete"
))
{
Thread
.
sleep
(
300
);
selectResult2
=
jdbc
.
findSimpleResult
(
"select * from orders_consumer.orders_0687 where order_num = '"
+
main_orderId
+
"' "
);
flowWork
=
String
.
valueOf
(
selectResult2
.
get
(
"flowwork_stage"
));
logger
.
info
(
"数据库订单节点:"
+
flowWork
);
j
--;
}
Assert
.
assertEquals
(
flowWork
,
"Success-complete"
,
"数据库主订单流程节点校验失败"
);
Assert
.
assertEquals
(
String
.
valueOf
(
selectResult2
.
get
(
"item_id"
)),
"31135"
,
"数据库主订单奖项id校验失败"
);
}
@Test
public
void
出奖实物订单校验
()
throws
Exception
{
Response
response
=
newActivityService
.
doJoin2
(
"31713"
,
"asdasd"
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
// logger.info("orderId=" + orderId );
response
=
newActivityService
.
getOrderStatus2
(
orderId
,
"iOS"
);
response
.
prettyPrint
();
String
result
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"result"
));
int
i
=
30
;
while
(
i
>
0
&&(
result
.
equals
(
"0"
))){
Thread
.
sleep
(
1000
);
response
=
newActivityService
.
getOrderStatus2
(
orderId
,
"iOS"
);
result
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"result"
));
i
--;
response
.
prettyPrint
();
}
String
type
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.type"
));
//领奖操作
String
recordId
=
MatcherString
.
getString
(
response
.
asString
(),
"recordId=(.*?)&"
,
1
);
response
=
newActivityService
.
doTakePrize
(
2720
,
type
,
recordId
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"message"
),
"领奖成功"
);
logger
.
info
(
"结果:"
+
type
+
"领奖流程成功"
);
Map
<
String
,
Object
>
selectResult
=
jdbc
.
findSimpleResult
(
"select * from credits_hdtool.hdtool_orders_0687 where id = '"
+
orderId
+
"'"
);
String
main_orderId
=
String
.
valueOf
(
selectResult
.
get
(
"main_order_num"
));
logger
.
info
(
"主订单为:"
+
main_orderId
);
Map
<
String
,
Object
>
selectResult2
=
jdbc
.
findSimpleResult
(
"select * from orders_consumer.orders_0687 where order_num = '"
+
main_orderId
+
"' "
);
String
flowWork
=
String
.
valueOf
(
selectResult2
.
get
(
"flowwork_stage"
));
logger
.
info
(
"领奖后数据库订单节点:"
+
flowWork
);
int
j
=
10
;
while
(
j
>
0
&&
!
flowWork
.
equals
(
"SupplierExchange-started"
))
{
Thread
.
sleep
(
300
);
selectResult2
=
jdbc
.
findSimpleResult
(
"select * from orders_consumer.orders_0687 where order_num = '"
+
main_orderId
+
"' "
);
flowWork
=
String
.
valueOf
(
selectResult2
.
get
(
"flowwork_stage"
));
logger
.
info
(
"领奖后数据库订单节点:"
+
flowWork
);
j
--;
}
Assert
.
assertEquals
(
flowWork
,
"SupplierExchange-started"
,
"数据库主订单流程节点校验失败"
);
Assert
.
assertEquals
(
String
.
valueOf
(
selectResult2
.
get
(
"item_id"
)),
"27131"
,
"数据库主订单奖项id校验失败"
);
Assert
.
assertEquals
(
String
.
valueOf
(
selectResult2
.
get
(
"biz_params"
)),
"胡梦新:18258853242:浙江省:杭州市:西湖区:数娱大厦"
,
"数据库主订单biz_params校验失败"
);
Assert
.
assertEquals
(
String
.
valueOf
(
selectResult2
.
get
(
"pay_status"
)),
"prereduce"
,
"数据库主订单pay_status校验失败"
);
Assert
.
assertEquals
(
String
.
valueOf
(
selectResult2
.
get
(
"status"
)),
"consume_success"
,
"数据库主订单status校验失败"
);
Map
<
String
,
Object
>
selectResult3
=
jdbc
.
findSimpleResult
(
"select * from credits_hdtool.hdtool_orders_0687 where id = '"
+
orderId
+
"'"
);
String
orderId_send
=
String
.
valueOf
(
selectResult3
.
get
(
"main_order_id"
));
logger
.
info
(
"发货订单为:"
+
orderId_send
);
//发货操作
managerService
.
expressSend
(
orderId_send
);
logger
.
info
(
"实物发货订单成功"
);
selectResult3
=
jdbc
.
findSimpleResult
(
"select * from orders_consumer.orders_0687 where order_num = '"
+
main_orderId
+
"'"
);
String
flowWork2
=
String
.
valueOf
(
selectResult3
.
get
(
"flowwork_stage"
));
logger
.
info
(
"发货后数据库订单节点:"
+
flowWork2
);
int
k
=
10
;
while
(
k
>
0
&&
!
flowWork2
.
equals
(
"Success-complete"
))
{
Thread
.
sleep
(
1000
);
selectResult3
=
jdbc
.
findSimpleResult
(
"select * from orders_consumer.orders_0687 where order_num = '"
+
main_orderId
+
"' "
);
flowWork2
=
String
.
valueOf
(
selectResult3
.
get
(
"flowwork_stage"
));
logger
.
info
(
"发货后数据库订单节点:"
+
flowWork2
);
k
--;
}
Assert
.
assertEquals
(
String
.
valueOf
(
selectResult3
.
get
(
"pay_status"
)),
"successs"
,
"数据库主订单pay_status校验失败"
);
Assert
.
assertEquals
(
String
.
valueOf
(
selectResult3
.
get
(
"status"
)),
"success"
,
"数据库主订单status校验失败"
);
}
public
String
getremind_db
(
String
gid
)
throws
Exception
{
Thread
.
sleep
(
1000
);
Map
map
=
jdbc
.
findSimpleResult
(
"select * from goods.item where id = "
+
gid
);
String
stock_id
=
String
.
valueOf
(
map
.
get
(
"stock_id"
));
Map
map2
=
jdbc
.
findSimpleResult
(
"select * from stock.tb_stock where stock_id = "
+
stock_id
);
String
stock
=
String
.
valueOf
(
map2
.
get
(
"stock"
));
return
stock
;
}
}
\ No newline at end of file
src/test/java/http/cases/NewActivityTest/多奖项中奖限制_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
com.alibaba.fastjson.JSON
;
import
base.DuibaTestBase
;
import
utils.PublicMethod
;
import
http.enums.ActivityDataTypeEnum
;
import
http.model.AwardVO
;
import
http.model.CustomHdToolVO
;
import
http.service.Activity.ManagerService
;
import
http.service.Activity.NewActivityService
;
import
http.service.hd.ActivityService
;
import
http.service.hd.CustomHdToolCtrlService
;
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.AfterClass
;
import
org.testng.annotations.Test
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Created by zhaoran on 2018/07/10
*/
public
class
多奖项中奖限制
_DuibaTest
extends
DuibaTestBase
{
@Autowired
NewActivityService
newActivityService
;
@Autowired
ManagerService
managerService
;
@Autowired
DeveloperService
developerService
;
@Autowired
CustomHdToolCtrlService
customHdToolCtrlService
;
@Autowired
ActivityService
activityService
;
private
static
DuibaLog
logger
=
DuibaLog
.
getLogger
();
//指定用户
private
static
int
uid
=
2720
;
//兑吧活动id
private
static
String
actId
;
//活动入库id
private
static
String
id
;
private
static
String
data
;
@AfterClass
public
void
after
()
throws
Exception
{
//数据库删除
try
{
jdbc
.
update
(
"delete from duiba_hdtool where title=?"
,
"【自动化】多奖项中奖限制"
+
data
);
jdbc
.
update
(
"delete from credits_dev.operating_activity where title=?"
,
"【自动化】多奖项中奖限制"
+
data
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
public
void
创建并上架活动
(
String
title
)
throws
Exception
{
//管理后台创建活动并开启
logger
.
info
(
"创建多奖项中奖限制活动"
);
CustomHdToolVO
customHdToolVO
=
new
CustomHdToolVO
();
customHdToolVO
.
setActId
(
null
);
customHdToolVO
.
setTitle
(
title
);
customHdToolVO
.
setFacePrice
(
"0.01"
);
customHdToolVO
.
setBrickId
(
167L
);
customHdToolVO
.
setFactoryKey
(
ActivityDataTypeEnum
.
HDTOOL
.
getKey
());
customHdToolVO
.
setOpenMutliPrizeLimit
(
true
);
AwardVO
awardVO1
=
AwardVO
.
谢谢参与
();
AwardVO
awardVO2
=
AwardVO
.
幸运福袋
();
AwardVO
awardVO3
=
AwardVO
.
话费充值
(
1
,
"多档位话费充值"
,
"话费"
,
"100"
,
"1"
,
true
,
null
);
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
(
"多奖项中奖限制活动"
);
Response
response
=
customHdToolCtrlService
.
saveOrEdit
(
customHdToolVO
);
Assert
.
assertTrue
(
response
.
jsonPath
().
getBoolean
(
"success"
));
actId
=
response
.
jsonPath
().
getString
(
"data.actId"
);
logger
.
info
(
"多奖项中奖限制兑吧活动id为:"
+
actId
);
managerService
.
switchSpecifyAndBlack
(
"1"
,
actId
);
//定向开发者
managerService
.
saveSpecify
(
actId
,
"2239"
);
//开发者上架活动
Response
HdResponse
=
developerService
.
joinIn
(
actId
,
"12"
);
logger
.
info
(
"创建活动并上架成功"
);
}
@Test
public
void
多奖项中奖限制测试
()
throws
Exception
{
data
=
PublicMethod
.
data
();
String
title
=
"【自动化】多奖项中奖限制"
+
data
;
this
.
创建并上架活动
(
title
);
//获取管理员后台活动信息
Response
ManagerResponse
=
managerService
.
edit
(
actId
);
//获取奖品剩余库存
String
appItemId
=
String
.
valueOf
(
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[2].appItemId"
));
logger
.
info
(
"预设必中奖品类型为:"
+
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[2].type"
));
logger
.
info
(
"预设中奖几率为:"
+
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[2].probability"
)+
"%"
);
logger
.
info
(
"预设中奖每人限制:"
+
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[2].limit"
)+
"次"
);
logger
.
info
(
"预设剩余奖品数:"
+
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[2].remaind"
)+
"个"
);
//获取入库id
ManagerResponse
=
developerService
.
list2
(
title
);
id
=
ManagerResponse
.
jsonPath
().
getString
(
"data.list[0].id"
);
//第一次抽奖
Response
response
=
this
.
新活动工具接口传参
(
id
,
"adsdas"
,
"iOS"
);
Assert
.
assertEquals
(
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.type"
)),
"phonebill"
,
"第一次抽奖出奖类型失败"
);
Assert
.
assertEquals
(
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.title"
)),
"话费"
,
"第一次抽奖出奖title失败"
);
//第二次抽奖
response
=
this
.
新活动工具接口传参
(
id
,
"adsdas"
,
"iOS"
);
// if(activityService.isRunning("10.110.10.12","17791","tuia-engine")){
//logger.info("tuia-engine服务启动成功");
Assert
.
assertEquals
(
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.type"
)),
"lucky"
,
"第二次抽奖出奖类型失败"
);
Assert
.
assertEquals
(
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.useBtnText"
)),
"马上使用"
,
"第二次抽奖出奖文案失败"
);
// }else{
// logger.info("tuia-engine服务启动未成功,福袋降级成谢谢参与!");
// Assert.assertEquals(response.jsonPath().getString("lottery.type"), "thanks", "校验类型失败");
// }
this
.
删除活动
();
}
public
void
删除活动
()
throws
Exception
{
//管理后台删除活动
managerService
.
delet
(
actId
);
logger
.
info
(
"管理后台删除活动成功!"
);
//开发者删除活动
developerService
.
delActivity
(
id
);
logger
.
info
(
"开发者后台删除活动成功!"
);
}
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
src/test/java/http/cases/NewActivityTest/奖品发放限制_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
com.alibaba.fastjson.JSON
;
import
base.DuibaTestBase
;
import
utils.PublicMethod
;
import
http.enums.ActivityDataTypeEnum
;
import
http.model.AwardVO
;
import
http.model.CustomHdToolVO
;
import
http.service.Activity.ManagerService
;
import
http.service.Activity.NewActivityService
;
import
http.service.hd.ActivityService
;
import
http.service.hd.CustomHdToolCtrlService
;
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.AfterClass
;
import
org.testng.annotations.Test
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Created by zhaoran on 2018/07/10
*/
public
class
奖品发放限制
_DuibaTest
extends
DuibaTestBase
{
@Autowired
NewActivityService
newActivityService
;
@Autowired
ManagerService
managerService
;
@Autowired
DeveloperService
developerService
;
@Autowired
CustomHdToolCtrlService
customHdToolCtrlService
;
@Autowired
ActivityService
activityService
;
private
static
DuibaLog
logger
=
DuibaLog
.
getLogger
();
//指定用户
private
static
int
uid
=
2720
;
//兑吧活动id
private
static
String
actId
;
//活动入库id
private
static
String
id
;
private
static
String
data
;
@AfterClass
public
void
after
()
throws
Exception
{
//数据库删除
try
{
jdbc
.
update
(
"delete from duiba_hdtool where title=?"
,
"【自动化】奖品发放限制"
+
data
);
jdbc
.
update
(
"delete from credits_dev.operating_activity where title=?"
,
"【自动化】奖品发放限制"
+
data
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
public
void
创建并上架活动
(
String
title
)
throws
Exception
{
//管理后台创建活动并开启
logger
.
info
(
"创建奖品发放限制活动"
);
CustomHdToolVO
customHdToolVO
=
new
CustomHdToolVO
();
customHdToolVO
.
setActId
(
null
);
customHdToolVO
.
setTitle
(
title
);
customHdToolVO
.
setFacePrice
(
"0.01"
);
customHdToolVO
.
setBrickId
(
167L
);
customHdToolVO
.
setFactoryKey
(
ActivityDataTypeEnum
.
HDTOOL
.
getKey
());
//奖品发放限制设置
customHdToolVO
.
setOpenPrizesGrantLimit
(
true
);
customHdToolVO
.
setPrizesGrantLimitDays
(
1
);
AwardVO
awardVO1
=
AwardVO
.
谢谢参与
();
AwardVO
awardVO2
=
AwardVO
.
幸运福袋
();
AwardVO
awardVO3
=
AwardVO
.
话费充值
(
1
,
"多档位话费充值"
,
"话费"
,
"100"
,
"1"
,
false
,
1
);
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
(
"奖品发放限制为1"
);
Response
response
=
customHdToolCtrlService
.
saveOrEdit
(
customHdToolVO
);
Assert
.
assertTrue
(
response
.
jsonPath
().
getBoolean
(
"success"
));
actId
=
response
.
jsonPath
().
getString
(
"data.actId"
);
logger
.
info
(
"多奖项中奖限制兑吧活动id为:"
+
actId
);
managerService
.
switchSpecifyAndBlack
(
"1"
,
actId
);
//定向开发者
managerService
.
saveSpecify
(
actId
,
"2239"
);
//开发者上架活动
Response
HdResponse
=
developerService
.
joinIn
(
actId
,
"12"
);
logger
.
info
(
"创建活动并上架成功"
);
}
@Test
public
void
奖品发放限制测试
()
throws
Exception
{
data
=
PublicMethod
.
data
();
String
title
=
"【自动化】奖品发放限制"
+
data
;
this
.
创建并上架活动
(
title
);
//获取管理员后台活动信息
Response
ManagerResponse
=
managerService
.
edit
(
actId
);
//获取奖品剩余库存
String
appItemId
=
String
.
valueOf
(
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[2].appItemId"
));
logger
.
info
(
"预设必中奖品类型为:"
+
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[2].type"
));
logger
.
info
(
"预设中奖几率为:"
+
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[2].probability"
)+
"%"
);
logger
.
info
(
"预设中奖每人限制:"
+
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[2].limit"
)+
"次"
);
logger
.
info
(
"预设剩余奖品数:"
+
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[2].remaind"
)+
"个"
);
//获取入库id
ManagerResponse
=
developerService
.
list2
(
title
);
id
=
ManagerResponse
.
jsonPath
().
getString
(
"data.list[0].id"
);
//第一次抽奖
Response
response
=
this
.
新活动工具接口传参
(
id
,
"adsdas"
,
"iOS"
);
Assert
.
assertEquals
(
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.type"
)),
"phonebill"
,
"第一次抽奖出奖类型失败"
);
Assert
.
assertEquals
(
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.title"
)),
"话费"
,
"第一次抽奖出奖title失败"
);
//第二次抽奖
response
=
this
.
新活动工具接口传参
(
id
,
"adsdas"
,
"iOS"
);
if
(
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.type"
)).
equals
(
"lucky"
)){
logger
.
info
(
"tuia-engine服务启动成功"
);
Assert
.
assertEquals
(
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.type"
)),
"lucky"
,
"第一次抽奖出奖类型失败"
);
Assert
.
assertEquals
(
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.useBtnText"
)),
"马上使用"
,
"第一次抽奖出奖文案失败"
);
}
else
{
logger
.
info
(
"tuia-engine服务启动未成功,福袋降级成谢谢参与!"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.type"
),
"thanks"
,
"校验类型失败"
);
}
this
.
删除活动
();
}
public
void
删除活动
()
throws
Exception
{
//管理后台删除活动
managerService
.
delet
(
actId
);
logger
.
info
(
"管理后台删除活动成功!"
);
//开发者删除活动
developerService
.
delActivity
(
id
);
logger
.
info
(
"开发者后台删除活动成功!"
);
}
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
=
30
;
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
src/test/java/http/cases/NewActivityTest/定向测试_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
base.DuibaTestBase
;
import
utils.PublicMethod
;
import
http.service.Activity.ManagerService
;
import
http.service.Activity.NewActivityService
;
import
http.service.Activity.NewtoolsService
;
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.AfterClass
;
import
org.testng.annotations.Test
;
/**
* Created by zhaoran on 2018/1/2
*/
public
class
定向测试
_DuibaTest
extends
DuibaTestBase
{
@Autowired
NewActivityService
newActivityService
;
@Autowired
ManagerService
managerService
;
@Autowired
Authorization
authorization
;
@Autowired
NewtoolsService
newtoolsService
;
@Autowired
DeveloperService
developerService
;
private
static
DuibaLog
logger
=
DuibaLog
.
getLogger
();
private
static
String
actId
;
private
static
String
data
;
@AfterClass
public
void
after
()
throws
Exception
{
//数据库删除
try
{
jdbc
.
update
(
"delete from hdtool_conf.duiba_hdtool where title=?"
,
"【定向测试数据】"
+
data
);
jdbc
.
update
(
"delete from credits_dev.operating_activity where title=?"
,
"【定向测试数据】"
+
data
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
@Test
(
description
=
"创建活动自动打开定向功能"
,
priority
=
1
)
public
void
a_
创建活动定向测试
()
throws
Exception
{
//管理后台创建活动并开启
data
=
PublicMethod
.
data
();
Response
ManagerResponse
=
managerService
.
save_random
(
"【定向测试数据】"
+
data
);
actId
=
ManagerResponse
.
jsonPath
().
getString
(
"actId"
);
managerService
.
switchSpecifyAndBlack
(
"1"
,
actId
);
ManagerResponse
=
managerService
.
list
(
"【定向测试数据】"
+
data
);
String
direct
=
ManagerResponse
.
jsonPath
().
getString
(
"data.page[0].direct"
);
Assert
.
assertEquals
(
direct
,
"true"
,
"校验创建活动自动打开定向功能失败"
);
Response
hdResponse
=
developerService
.
list
(
"2239"
);
String
title
=
hdResponse
.
jsonPath
().
getString
(
"data[0].title"
);
// Assert.assertNotEquals(title, "【推荐位测试数据】", "校验开发者集市定向活动失败,应不展示未定向到2239活动");
Assert
.
assertEquals
(
title
.
equals
(
"【定向测试数据】"
+
data
),
false
,
"校验开发者集市定向活动失败,应不展示未定向到2239活动!"
);
}
// @Test(description = "打开定向功能未指定开发者",priority = 2)
// public void b_未指定定向开发者测试() throws Exception {
//
// //查询对应开发者集市
// Response hdResponse = developerService.list("2239");
// String title = hdResponse.jsonPath().getString("data[0].title");
// // Assert.assertNotEquals(title, "【推荐位测试数据】", "校验开发者集市定向活动失败,应不展示未定向到2239活动");
// Assert.assertEquals(title.equals("【推荐位测试数据】"), false,"校验开发者集市定向活动失败,应不展示未定向到2239活动!");
//
// }
@Test
(
description
=
"打开定向功能指定开发者"
,
priority
=
3
)
public
void
c_
定向开发者测试
()
throws
Exception
{
//定向开发者
managerService
.
saveSpecify
(
actId
,
"2239"
);
//查询对应开发者集市
Response
hdResponse
=
developerService
.
list
(
"2239"
);
//String title = hdResponse.jsonPath().getString("data[0].title");
for
(
int
z
=
0
;
z
<
6
;
z
++){
String
title2
=
hdResponse
.
jsonPath
().
getString
(
"data["
+
z
+
"].title"
);
logger
.
info
(
"第"
+
z
+
"个活动名称为"
+
title2
);
if
(
title2
.
equals
(
"【定向测试数据】"
+
data
)){
// Assert.assertEquals(title2, "【定向测试数据】"+data, "校验开发者集市定向活动失败,应展示定向到2239的活动");
break
;
}
if
(
z
==
5
){
throw
new
Exception
(
"校验开发者集市定向活动失败,应展示定向到2239的活动"
);
}
}
}
@Test
(
description
=
"关闭活动定向功能"
,
priority
=
4
)
public
void
d_
关闭定向测试
()
throws
Exception
{
//取消定向开发者
managerService
.
switchSpecify
(
"false"
,
actId
,
"0"
);
//查询对应开发者集市
Response
hdResponse
=
developerService
.
list
(
"2239"
);
for
(
int
z
=
0
;
z
<
6
;
z
++){
String
title2
=
hdResponse
.
jsonPath
().
getString
(
"data["
+
z
+
"].title"
);
logger
.
info
(
"第"
+
z
+
"个活动名称为"
+
title2
);
if
(
title2
.
equals
(
"【定向测试数据】"
+
data
)){
// Assert.assertEquals(title2, "【定向测试数据】"+data, "校验开发者集市定向活动失败,应展示定向到2239的活动");
break
;
}
if
(
z
==
5
){
throw
new
Exception
(
"校验开发者集市定向活动失败,应展示未开启定向活动"
);
}
}
// String title = hdResponse.jsonPath().getString("data[0].title");
// Assert.assertEquals(title, "【定向测试数据】"+data, "校验开发者集市定向活动失败,应展示未开启定向活动");
}
//@Test(description = "数据后置清理",priority = 5)
public
void
e_
删除活动
()
throws
Exception
{
//管理后台删除推荐位活动
managerService
.
delet
(
actId
);
//管理后台删除推荐位活动
// Response ManagerResponse = managerService.list();
// String mactId = ManagerResponse.jsonPath().getString("data.page[0].id");
// managerService.delet(mactId);
}
}
\ No newline at end of file
src/test/java/http/cases/NewActivityTest/扣库存测试_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
base.DuibaTestBase
;
import
http.service.Activity.ManagerService
;
import
http.service.Activity.NewActivityService
;
import
http.service.hd.DeveloperService
;
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.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 zhaoran on 2018/1/2
*/
public
class
扣库存测试
_DuibaTest
extends
DuibaTestBase
{
@Autowired
NewActivityService
newActivityService
;
@Autowired
ManagerService
managerService
;
@Autowired
DeveloperService
developerService
;
private
static
DuibaLog
logger
=
DuibaLog
.
getLogger
();
@DataProvider
public
Iterator
<
Object
[]>
providerMethod
(
Method
method
)
throws
IOException
{
Iterator
<
Object
[]>
result
=
null
;
if
(
method
.
getName
().
equals
(
"活动工具扣库存测试"
))
{
result
=
new
ExcelDataProvider
(
"duiba/扣库存测试"
);
}
return
result
;
}
@Test
(
dataProvider
=
"providerMethod"
,
description
=
"历史活动扣库存逻辑,无stock_id"
)
public
void
活动工具扣库存测试
(
Map
<
String
,
String
>
data
)
throws
Exception
{
logger
.
info
(
"-------------------------------------"
+
data
.
get
(
"casename"
)+
"-------------------------------------"
);
//获取兑换项库存
String
remind
=
this
.
getremind_db
(
data
.
get
(
"gid"
));
//扣去1库存
remind
=
String
.
valueOf
(
Integer
.
valueOf
(
remind
)-
1
);
//获取奖项库存
Map
map
=
jdbc
.
findSimpleResult
(
"select * from credits_activity.act_pre_stock where relation_type = 'hdtool' and relation_config_id = "
+
data
.
get
(
"actId"
));
String
db_quantity
=
String
.
valueOf
(
map
.
get
(
"prize_quantity"
));
//扣去1库存
db_quantity
=
String
.
valueOf
(
Integer
.
valueOf
(
db_quantity
)-
1
);
Response
response
=
this
.
新活动工具接口传参
(
data
.
get
(
"activityId"
),
data
.
get
(
"token"
),
"iOS"
);
String
type
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.type"
));
if
(
type
.
equals
(
"virtual"
)){
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.link"
).
contains
(
"/activity/takePrizeNew?recordId="
));
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
),
"11612"
,
"校验id失败"
);
logger
.
info
(
"校验虚拟商品:link,id成功"
);
}
if
(
type
.
equals
(
"collectGoods"
)){
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.itemId"
),
"27133"
,
"校验itemId失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
),
"11614"
,
"校验id失败"
);
logger
.
info
(
"校验集卡商品:link,id成功"
);
}
if
(
type
.
equals
(
"object"
)){
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.title"
),
"实物奖品"
,
"校验title失败"
);
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.link"
).
contains
(
"/activity/takePrizeNew?recordId="
));
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
),
"11604"
,
"校验id失败"
);
logger
.
info
(
"校验实物商品:link,id成功"
);
}
//校验兑换项库存
String
Newremind
=
this
.
getremind_db
(
data
.
get
(
"gid"
));
Assert
.
assertEquals
(
Newremind
,
remind
);
logger
.
info
(
"校验抽奖前后兑换项库存正确"
);
//获取页面奖项库存库存
response
=
managerService
.
getDataEditConfig
(
data
.
get
(
"actId"
));
String
showRemind
=
response
.
jsonPath
().
getString
(
"awards[1].remaind"
);
logger
.
info
(
"校验后页面展示库存为:"
+
showRemind
);
//校验奖项库存
Assert
.
assertEquals
(
showRemind
,
db_quantity
);
logger
.
info
(
"校验抽奖前后奖项库存正确"
);
}
@Test
public
void
闯关活动扣库存测试
()
throws
Exception
{
//获取兑换项库存
String
remind
=
this
.
getremind_db
(
"27000"
);
//扣去1库存
remind
=
String
.
valueOf
(
Integer
.
valueOf
(
remind
)-
1
);
//获取奖项库存
String
db_quantity
=
this
.
getremind_pre
(
"7116"
,
"0"
);
//扣去1库存
db_quantity
=
String
.
valueOf
(
Integer
.
valueOf
(
db_quantity
)-
1
);
Response
response
=
newActivityService
.
doJoin2
(
"28050"
,
"abcde"
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
response
.
prettyPrint
();
response
=
newActivityService
.
throughSubmit
(
orderId
);
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
response
=
newActivityService
.
getOrderStatus2
(
orderId
,
"iOS"
);
response
.
prettyPrint
();
String
result
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"result"
));
int
i
=
30
;
while
(
i
>
0
&&(
result
.
equals
(
"0"
))){
Thread
.
sleep
(
1000
);
response
=
newActivityService
.
getOrderStatus2
(
orderId
,
"iOS"
);
result
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"result"
));
i
--;
response
.
prettyPrint
();
}
String
type
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.type"
));
Assert
.
assertEquals
(
type
,
"object"
,
"校验type失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.title"
),
"自动化实物"
,
"校验title失败"
);
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.link"
).
contains
(
"/activity/takePrizeNew?recordId="
));
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
),
"19338"
,
"校验id失败"
);
logger
.
info
(
"校验实物商品:title,link,id成功"
);
//校验兑换项库存
String
Newremind
=
this
.
getremind_db
(
"27000"
);
Assert
.
assertEquals
(
Newremind
,
remind
);
logger
.
info
(
"校验抽奖前后兑换项库存正确"
);
//获取页面奖项库存库存
response
=
managerService
.
edit
(
"7116"
);
String
showRemind
=
response
.
jsonPath
().
getString
(
"data.awards[1].remaind"
);
logger
.
info
(
"校验后页面展示库存为:"
+
showRemind
);
//校验奖项库存
Assert
.
assertEquals
(
showRemind
,
db_quantity
);
logger
.
info
(
"校验抽奖前后奖项库存正确"
);
}
@Test
public
void
自定义活动扣库存测试
()
throws
Exception
{
//获取兑换项库存
String
remind
=
this
.
getremind_db
(
"27000"
);
//扣去1库存
remind
=
String
.
valueOf
(
Integer
.
valueOf
(
remind
)-
1
);
//获取奖项库存
String
db_quantity
=
this
.
getremind_pre
(
"8788"
,
"0"
);
//扣去1库存
db_quantity
=
String
.
valueOf
(
Integer
.
valueOf
(
db_quantity
)-
1
);
Response
response
=
this
.
新活动工具接口传参
(
"31116"
,
"abcde"
,
"iOS"
);
String
type
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.type"
));
Assert
.
assertEquals
(
type
,
"object"
,
"校验type失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.title"
),
"测试实物"
,
"校验title失败"
);
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.link"
).
contains
(
"/activity/takePrizeNew?recordId="
));
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
),
"21780"
,
"校验id失败"
);
logger
.
info
(
"校验实物商品:title,link,id成功"
);
//校验兑换项库存
String
Newremind
=
this
.
getremind_db
(
"27000"
);
Assert
.
assertEquals
(
Newremind
,
remind
);
logger
.
info
(
"校验抽奖前后兑换项库存正确"
);
//获取页面奖项库存库存
response
=
managerService
.
edit
(
"8788"
);
String
showRemind
=
response
.
jsonPath
().
getString
(
"data.awards[1].remaind"
);
logger
.
info
(
"校验后页面展示库存为:"
+
showRemind
);
//校验奖项库存
Assert
.
assertEquals
(
showRemind
,
db_quantity
);
logger
.
info
(
"校验抽奖前后奖项库存正确"
);
}
@Test
public
void
预分配扣库存测试
()
throws
Exception
{
//获取兑换项库存
String
remind
=
this
.
getremind_db
(
"27000"
);
//扣去1库存
remind
=
String
.
valueOf
(
Integer
.
valueOf
(
remind
)-
1
);
//获取奖项库存
String
db_quantity_org
=
this
.
getremind_pre
(
"8789"
,
"0"
);
//获取预分配库存
String
db_quantity_allo
=
this
.
getremind_pre
(
"8789"
,
"2239"
);
//预分配扣去1库存(预期值)
db_quantity_allo
=
String
.
valueOf
(
Integer
.
valueOf
(
db_quantity_allo
)-
1
);
Response
response
=
this
.
新活动工具接口传参
(
"31117"
,
"abcde"
,
"iOS"
);
String
type
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.type"
));
Assert
.
assertEquals
(
type
,
"object"
,
"校验type失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.title"
),
"测试实物"
,
"校验title失败"
);
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.link"
).
contains
(
"/activity/takePrizeNew?recordId="
));
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
),
"21782"
,
"校验id失败"
);
logger
.
info
(
"校验实物商品:title,link,id成功"
);
//校验兑换项库存
String
Newremind
=
this
.
getremind_db
(
"27000"
);
Assert
.
assertEquals
(
Newremind
,
remind
);
logger
.
info
(
"校验抽奖前后兑换项库存正确"
);
//校验奖项库存
String
db_quantity_org_later
=
this
.
getremind_pre
(
"8789"
,
"0"
);
Assert
.
assertEquals
(
db_quantity_org_later
,
db_quantity_org
,
"校验抽奖前后校验奖项库存失败"
);
logger
.
info
(
"校验抽奖前后奖项项库存正确"
);
//校验预分配库存
String
db_quantity_allo_later
=
this
.
getremind_pre
(
"8789"
,
"2239"
);
Assert
.
assertEquals
(
db_quantity_allo_later
,
db_quantity_allo
,
"校验抽奖前后校验奖项库存失败"
);
logger
.
info
(
"校验抽奖前后预分配库存正确"
);
}
@Test
public
void
自有活动工具扣库存测试
()
throws
Exception
{
//获取兑换项库存
Response
response
=
developerService
.
appItems
(
"2239"
,
"【自动化勿动】自有优惠券"
);
//response.prettyPrint();
String
remind
=
response
.
jsonPath
().
getString
(
"data.list[0].remaind"
);
logger
.
info
(
"抽奖前兑换项库存为:"
+
remind
);
//扣去1库存
remind
=
String
.
valueOf
(
Integer
.
valueOf
(
remind
)-
1
);
//获取奖项库存
Map
map
=
jdbc
.
findSimpleResult
(
"select * from credits_dev.operating_activity_options where id = 16405"
);
String
db_quantity
=
String
.
valueOf
(
map
.
get
(
"remaining"
));
logger
.
info
(
"抽奖前奖项库存为:"
+
db_quantity
);
//扣去1库存
db_quantity
=
String
.
valueOf
(
Integer
.
valueOf
(
db_quantity
)-
1
);
response
=
this
.
新活动工具接口传参
(
"28247"
,
"abcde"
,
"iOS"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.type"
),
"coupon"
,
"校验type失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.title"
),
"【自动化勿动】自有优惠券"
,
"校验title失败"
);
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.link"
).
contains
(
"/crecord/recordDetailNew?orderId="
));
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
),
"16405"
,
"校验id失败"
);
logger
.
info
(
"校验实物商品:type,title,link,id成功"
);
//校验兑换项库存
response
=
developerService
.
appItems
(
"2239"
,
"【自动化勿动】自有优惠券"
);
String
Newremind
=
response
.
jsonPath
().
getString
(
"data.list[0].remaind"
);
int
i
=
10
;
while
(
i
>
0
&&
!
Newremind
.
equals
(
remind
)){
Thread
.
sleep
(
500
);
response
=
developerService
.
appItems
(
"2239"
,
"【自动化勿动】自有优惠券"
);
Newremind
=
response
.
jsonPath
().
getString
(
"data.list[0].remaind"
);
i
--;
}
logger
.
info
(
"抽奖后兑换项库存为:"
+
Newremind
);
Assert
.
assertEquals
(
Newremind
,
remind
);
logger
.
info
(
"校验抽奖前后兑换项库存正确"
);
//获取页面奖项库存库存
// response = developerService.appItems("2239","【自动化勿动】自有优惠券");
// String showRemind = response.jsonPath().getString("awards[1].remaind");
// logger.info("校验后页面展示库存为:"+showRemind);
//获取奖项库存
map
=
jdbc
.
findSimpleResult
(
"select * from credits_dev.operating_activity_options where id = 16405"
);
String
db_quantity_new
=
String
.
valueOf
(
map
.
get
(
"remaining"
));
logger
.
info
(
"抽奖后奖项库存为:"
+
db_quantity_new
);
//校验奖项库存
Assert
.
assertEquals
(
db_quantity_new
,
db_quantity
);
logger
.
info
(
"校验抽奖前后奖项库存正确"
);
}
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
=
30
;
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
;
}
public
String
getremind
(
String
gid
)
throws
Exception
{
Thread
.
sleep
(
1000
);
Response
ManagerResponse
=
managerService
.
CouponConfig
(
gid
);
ManagerResponse
.
prettyPrint
();
String
remind
=
MatcherString
.
getString
(
ManagerResponse
.
asString
(),
"remaining\" value=\"(.*?)\""
,
1
);
logger
.
info
(
"当前库存:"
+
remind
);
return
remind
;
}
public
String
getremind_db
(
String
gid
)
throws
Exception
{
Thread
.
sleep
(
1000
);
Map
map
=
jdbc
.
findSimpleResult
(
"select * from goods.item where id = "
+
gid
);
String
stock_id
=
String
.
valueOf
(
map
.
get
(
"stock_id"
));
Map
map2
=
jdbc
.
findSimpleResult
(
"select * from stock.tb_stock where stock_id = "
+
stock_id
);
String
stock
=
String
.
valueOf
(
map2
.
get
(
"stock"
));
return
stock
;
}
public
String
getremind_pre
(
String
actId
,
String
appId
)
throws
Exception
{
Thread
.
sleep
(
1000
);
Map
map
=
jdbc
.
findSimpleResult
(
"select * from credits_activity.act_pre_stock where relation_config_id = "
+
actId
+
" and app_id = "
+
appId
+
""
);
String
stock_id
=
String
.
valueOf
(
map
.
get
(
"stock_id"
));
Map
map2
=
jdbc
.
findSimpleResult
(
"select * from stock.tb_stock where stock_id = "
+
stock_id
);
String
db_quantity
=
String
.
valueOf
(
map2
.
get
(
"stock"
));
return
db_quantity
;
}
}
\ No newline at end of file
src/test/java/http/cases/NewActivityTest/抽奖异常测试_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
base.DuibaTestBase
;
import
http.service.Activity.ManagerService
;
import
http.service.Activity.NewActivityService
;
import
http.service.Authorization
;
import
http.service.hd.DeveloperService
;
import
http.service.hd.SigninService
;
import
utils.MatcherString
;
import
utils.ExcelDataProvider
;
import
base.DuibaLog
;
import
base.MysqlUtils
;
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.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
;
/**
* Created by zhaoran on 2018/1/2
*/
public
class
抽奖异常测试
_DuibaTest
extends
DuibaTestBase
{
@Autowired
NewActivityService
newActivityService
;
@Autowired
ManagerService
managerService
;
@Autowired
SigninService
signinService
;
@Autowired
Authorization
authorization
;
@Autowired
DeveloperService
developerService
;
private
static
DuibaLog
logger
=
DuibaLog
.
getLogger
();
private
MysqlUtils
jdbc
;
private
String
url
=
"http://activity.m.duibatest.com.cn"
;
@DataProvider
public
Iterator
<
Object
[]>
providerMethod
(
Method
method
)
throws
IOException
{
Iterator
<
Object
[]>
result
=
null
;
if
(
method
.
getName
().
equals
(
"限制抽奖测试"
))
{
result
=
new
ExcelDataProvider
(
"duiba/限制抽奖数据"
);
}
else
if
(
method
.
getName
().
equals
(
"未登录抽奖测试"
))
{
result
=
new
ExcelDataProvider
(
"duiba/未登录抽奖数据"
);
}
else
if
(
method
.
getName
().
equals
(
"中奖限制测试"
))
{
result
=
new
ExcelDataProvider
(
"duiba/中奖限制数据"
);
}
return
result
;
}
// @DataProvider
// public Object[][] providerData(Method method){
// Object[][] result = null;
// if(method.getName().equals("活动黑名单测试")) {
// result = new Object[][]{
// new Object[]{"18900","3026", "true"},
// new Object[]{"18900","3026", "false"},};
// }
// return result;
// }
@Test
public
void
活动关闭测试
()
throws
Exception
{
//关闭活动
Response
HdResponse
=
developerService
.
closeActivity
(
"18583"
,
"2239"
);
//打开活动界面
Response
response
=
newActivityService
.
index
(
"18583"
);
//判断结果
Assert
.
assertEquals
(
MatcherString
.
getString
(
response
.
asString
(),
"<title>(.*?)</title>\n"
,
1
),
"活动结束"
,
"活动页打开异常!"
);
logger
.
info
(
"活动状态关闭后的抽奖验证成功"
);
//打开活动
HdResponse
=
developerService
.
openActivity
(
"18583"
,
"2239"
);
}
@Test
public
void
扣积分失败测试
()
throws
Exception
{
managerService
.
index
();
try
{
//修改活动扣积分模板 consumeTemplateId: 1-扣积分成功;2-扣积分失败
Response
HdResponse
=
managerService
.
doEdit2
(
"2"
);
//进行接口测试传参
Response
response
=
this
.
新活动工具接口传参失败
(
"27018"
,
"q1l0ry"
);
//判断结果
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"message"
),
"扣积分-失败测试"
,
"校验message失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"result"
),
"101"
,
"校验result失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"false"
,
"校验success失败"
);
logger
.
info
(
"扣积分失败测试验证成功"
);
}
catch
(
Exception
e
)
{
throw
new
Exception
(
"扣积分失败测试!"
);
}
finally
{
//还原活动扣积分模板 consumeTemplateId: 1-扣积分成功;2-扣积分失败
Response
HdResponse
=
managerService
.
doEdit2
(
"1"
);
}
}
@Test
(
dataProvider
=
"providerMethod"
)
public
void
限制抽奖测试
(
Map
<
String
,
String
>
data
)
throws
Exception
{
logger
.
info
(
"-------------------------------------"
+
data
.
get
(
"casename"
)+
"-------------------------------------"
);
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"activityId"
,
data
.
get
(
"activityId"
));
map
.
put
(
"token"
,
data
.
get
(
"token"
));
logger
.
info
(
"请求/hdtool/doJoin接口"
);
Response
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
2720
)).
params
(
map
).
post
(
url
+
"/hdtool/doJoin"
);
response
.
prettyPrint
();
//根据case选择对应的校验项
int
casenum
=
Integer
.
parseInt
(
data
.
get
(
"casenum"
));
switch
(
casenum
){
case
1
:
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"message"
),
"积分不足"
,
"校验message失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"status"
),
"1"
,
"校验status失败"
);
logger
.
info
(
"积分不足测试校验项:message,status成功"
);
break
;
case
2
:
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"message"
),
"永久次数已用完"
,
"校验message失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"status"
),
"4"
,
"校验status失败"
);
logger
.
info
(
"永久次数不足测试校验项:message,status成功"
);
break
;
case
3
:
String
success
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"success"
));
int
i
=
8
;
while
(
i
>
0
&&(
success
.
equals
(
"true"
))){
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
2720
)).
params
(
map
).
post
(
url
+
"/newActivity/doJoin"
);
success
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"success"
));
i
--;
}
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"message"
),
"今日次数已用完"
,
"校验message失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"status"
),
"3"
,
"校验status失败"
);
logger
.
info
(
"今日次数不足测试校验项:message,status成功"
);
break
;
}
//通用校验项
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"false"
,
"校验success失败"
);
logger
.
info
(
"通用校验项:success成功"
);
Thread
.
sleep
(
3000
);
}
@Test
(
dataProvider
=
"providerMethod"
)
public
void
未登录抽奖测试
(
Map
<
String
,
String
>
data
)
throws
Exception
{
logger
.
info
(
"-------------------------------------"
+
data
.
get
(
"casename"
)+
"-------------------------------------"
);
//获取未登录场景cookie
Response
responses
=
authorization
.
autoLogin
();
//进行接口测试传参
Response
response
=
newActivityService
.
doJoin
(
responses
.
getDetailedCookies
(),
data
.
get
(
"token"
),
data
.
get
(
"activityId"
));
response
.
prettyPrint
();
String
success
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"success"
));
//根据case选择校验项
if
(
success
.
equals
(
"false"
)){
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"message"
),
"请先登录"
,
"校验message失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"status"
),
"18"
,
"校验status失败"
);
logger
.
info
(
"未登录状态下无免费次数抽奖校验:message,status成功"
);
}
if
(
success
.
equals
(
"true"
)){
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
response
=
newActivityService
.
getOrderStatus
(
responses
.
getDetailedCookies
(),
orderId
);
response
.
prettyPrint
();
String
result
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"result"
));
int
i
=
8
;
while
(
i
>
0
&&(
result
.
equals
(
"0"
))){
Thread
.
sleep
(
1000
);
response
=
newActivityService
.
getOrderStatus
(
responses
.
getDetailedCookies
(),
orderId
);
result
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"result"
));
i
--;
response
.
prettyPrint
();
}
response
.
prettyPrint
();
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.title"
),
"话费"
,
"校验title失败"
);
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.link"
).
contains
(
"/activity/takePrizeNew?recordId="
));
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
),
"11628"
,
"校验id失败"
);
logger
.
info
(
"未登录状态下有免费次数抽奖校验:title,link,id成功"
);
}
}
@Test
(
dataProvider
=
"providerMethod"
)
public
void
中奖限制测试
(
Map
<
String
,
String
>
data
)
throws
Exception
{
logger
.
info
(
"-------------------------------------"
+
data
.
get
(
"casename"
)+
"-------------------------------------"
);
//获取管理员后台活动信息
Response
ManagerResponse
=
managerService
.
edit
(
data
.
get
(
"actId"
));
//获取奖品剩余库存
String
appItemId
=
String
.
valueOf
(
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[1].appItemId"
));
String
Objremaind
=
this
.
getremind
(
appItemId
);
logger
.
info
(
"预设必中奖品类型为:"
+
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[1].type"
));
logger
.
info
(
"预设中奖几率为:"
+
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[1].probability"
)+
"%"
);
logger
.
info
(
"预设中奖每人限制:"
+
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[1].limit"
)+
"次"
);
logger
.
info
(
"预设剩余奖品数:"
+
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[1].remaind"
)+
"个"
);
logger
.
info
(
"预设奖品库存:"
+
Objremaind
+
"个"
);
if
(
Objremaind
.
equals
(
"0"
)){
Assert
.
assertEquals
(
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[1].valid"
),
"false"
,
"校验奖品是否有效失败"
);
}
//进行接口测试传参
Response
response
=
this
.
新活动工具接口传参
(
data
.
get
(
"activityId"
),
data
.
get
(
"token"
),
"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
(
"校验中奖限制测试成功,未返回预设必中"
+
ManagerResponse
.
jsonPath
().
getString
(
"data.awards[1].type"
)+
"奖品"
);
}
if
(
type
.
equals
(
"thanks"
)){
logger
.
info
(
"福袋库存不足会降级成谢谢参与!"
);
//福袋库存不足会降级成谢谢参与!
}
if
(
type
.
equals
(
"object"
)&&
ManagerResponse
.
jsonPath
().
getString
(
"awards[1].remaind"
).
equals
(
"0"
)){
throw
new
Exception
(
"用例失败,不应返回实物信息:"
+
response
.
asString
());
}
}
//@Test(dataProvider = "providerData")
public
void
活动黑名单测试
test
(
String
id
,
String
activityId
,
String
status
)
throws
Exception
{
//将开发者ID加入活动的黑名单
Response
HdResponse
=
managerService
.
switchBlack
(
activityId
,
status
);
Thread
.
sleep
(
60000
);
//打开活动界面
Response
response
=
newActivityService
.
index
(
id
);
//判断结果
if
(
status
.
equals
(
"true"
)){
Assert
.
assertEquals
(
MatcherString
.
getString
(
response
.
asString
(),
"<title>(.*?)</title>\n"
,
1
),
"活动结束"
,
"活动页打开异常!"
);
}
else
{
Assert
.
assertEquals
(
MatcherString
.
getString
(
response
.
asString
(),
"<title>(.*?)</title>\n"
,
1
),
"【勿动】自动化—黑名单"
,
"活动页打开异常!"
);
}
logger
.
info
(
"黑名单开关的抽奖页面验证成功"
);
}
@Test
public
void
活动黑名单测试
()
throws
Exception
{
//打开活动界面
Response
response
=
newActivityService
.
index
(
"18900"
);
//判断结果
Assert
.
assertEquals
(
MatcherString
.
getString
(
response
.
asString
(),
"<title>(.*?)</title>\n"
,
1
),
"活动结束"
,
"活动页打开异常!"
);
logger
.
info
(
"黑名单开关的抽奖页面验证成功"
);
}
//@Test
public
void
活动保底测试
()
throws
Exception
{
//获取管理员后台活动信息
// Response ManagerResponse = managerService.getDataEditConfig("3146");
//获取奖品剩余库存
// String low = String.valueOf(ManagerResponse.jsonPath().getString("awards[1].low"));
// logger.info("奖品保底人数:"+low+"人");
//设置活动保底人数
Response
ManagerResponse
=
managerService
.
save
(
"3146"
,
"【勿动】自动化-保底人数"
,
"0"
,
"80"
);
}
@Test
(
description
=
"该活动已在大富翁app上架可参与"
)
public
void
开发者未上架活动
(){
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"activityId"
,
"33486"
);
map
.
put
(
"token"
,
"u73vb2oxn"
);
logger
.
info
(
"请求/hdtool/doJoin接口,activityId=33486"
);
Response
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
2720
)).
params
(
map
).
post
(
url
+
"/hdtool/doJoin"
);
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
=
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
;
}
public
Response
新活动工具接口传参失败
(
String
activityId
,
String
token
)
throws
Exception
{
Response
response
=
newActivityService
.
doJoin2
(
3268
,
activityId
,
token
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
response
=
newActivityService
.
getOrderStatus2
(
3268
,
orderId
);
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
(
3268
,
orderId
);
result
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"result"
));
i
--;
response
.
prettyPrint
();
}
return
response
;
}
public
String
getremind
(
String
gid
)
throws
Exception
{
Response
ManagerResponse
=
managerService
.
CouponConfig
(
gid
);
ManagerResponse
.
prettyPrint
();
String
remind
=
MatcherString
.
getString
(
ManagerResponse
.
asString
(),
"remaining\" value=\"(.*?)\""
,
1
);
//logger.info("当前库存:"+remind);
return
remind
;
}
}
\ No newline at end of file
src/test/java/http/cases/NewActivityTest/推荐位测试_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
base.DuibaTestBase
;
import
utils.PublicMethod
;
import
http.service.Activity.ManagerService
;
import
http.service.Activity.NewActivityService
;
import
http.service.Activity.NewtoolsService
;
import
http.service.Authorization
;
import
http.service.hd.DeveloperService
;
import
utils.MatcherString
;
import
base.DuibaLog
;
import
io.restassured.http.Cookies
;
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
;
/**
* Created by zhaoran on 2018/1/2
*/
public
class
推荐位测试
_DuibaTest
extends
DuibaTestBase
{
@Autowired
NewActivityService
newActivityService
;
@Autowired
ManagerService
managerService
;
@Autowired
Authorization
authorization
;
@Autowired
NewtoolsService
newtoolsService
;
@Autowired
DeveloperService
developerService
;
private
static
DuibaLog
logger
=
DuibaLog
.
getLogger
();
private
static
String
data
;
private
static
String
actId
;
@AfterClass
public
void
after
()
throws
Exception
{
//数据库删除
try
{
jdbc
.
update
(
"delete from hdtool_conf.duiba_hdtool where title=?"
,
"【推荐位测试数据】"
+
data
);
jdbc
.
update
(
"delete from credits_dev.operating_activity where title=?"
,
"【推荐位测试数据】"
+
data
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
);
}
}
@Test
(
description
=
"数据前置准备"
,
priority
=
1
)
public
void
a_
创建并上架活动
()
throws
Exception
{
//管理后台创建活动并开启
data
=
PublicMethod
.
data
();
Response
ManagerResponse
=
managerService
.
save_random
(
"【推荐位测试数据】"
+
data
);
actId
=
ManagerResponse
.
jsonPath
().
getString
(
"actId"
);
managerService
.
switchSpecifyAndBlack
(
"1"
,
actId
);
//定向开发者
managerService
.
saveSpecify
(
actId
,
"2239"
);
//开发者上架活动
Response
HdResponse
=
developerService
.
joinIn
(
actId
,
"12"
);
logger
.
info
(
"创建活动并上架成功,推荐位中应有数据"
);
}
@Test
(
priority
=
2
)
public
void
b_
浮标推荐位测试
()
throws
Exception
{
logger
.
info
(
"-------------------------------------应用推荐位:开;活动推荐位:开;浮标推荐位开-------------------------------------"
);
//打开app应用推荐位
// managerService.updateAppConfig("on","off");
logger
.
info
(
"app应用推荐位推荐位开关:on"
);
//打开活动应用推荐位
// Response ManagerResponse = managerService.save("2726","【勿动】自动化—推荐位","OPEN");
logger
.
info
(
"活动推荐位开关:OPEN"
);
//登录游戏
Cookies
cookies
=
newtoolsService
.
getCookies
(
"18602"
,
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
);
Response
responses
=
newtoolsService
.
autoLogin
(
cookies
,
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
);
Response
response1
=
newtoolsService
.
index
(
responses
.
getDetailedCookies
(),
"18602"
);
String
isOpenRecommend
=
MatcherString
.
getString
(
response1
.
asString
(),
"isOpenRecommend: (.*?),"
,
1
);
logger
.
info
(
"是否展示推荐位:"
+
isOpenRecommend
);
//校验推荐位
Assert
.
assertEquals
(
isOpenRecommend
,
"true"
,
"校验是否展示推荐位结果失败"
);
Response
response
=
newActivityService
.
getRecommend
(
"18602"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验结果失败"
);
if
(
response
.
jsonPath
().
getString
(
"recommendQueueList[0].title"
).
contains
(
"测试"
)){
logger
.
info
(
"校验推荐位:title成功"
);
}
else
if
(
response
.
jsonPath
().
getString
(
"recommendQueueList[1].title"
).
contains
(
"测试"
)){
logger
.
info
(
"校验推荐位:title成功"
);
}
else
{
throw
new
Exception
(
"推荐位校验异常,请确认!"
);
}
logger
.
info
(
"校验推荐位:title成功"
);
}
@Test
(
priority
=
3
)
public
void
c_
活动关闭推荐位测试
()
throws
Exception
{
//关闭活动
Response
HdResponse
=
developerService
.
closeActivity
(
"18583"
,
"2239"
);
//打开活动界面
Response
response
=
newActivityService
.
index
(
"18583"
);
Assert
.
assertEquals
(
MatcherString
.
getString
(
response
.
asString
(),
"recommendTpl\">\n"
+
" <p>(.*?)<"
,
1
),
"看看其他活动吧"
,
"活动页打开异常!"
);
//登录游戏
Cookies
cookies
=
newtoolsService
.
getCookies
(
"18583"
,
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
);
Response
responses
=
newtoolsService
.
autoLogin
(
cookies
,
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
);
Response
response1
=
newtoolsService
.
index
(
responses
.
getDetailedCookies
(),
"18583"
);
//校验推荐位
response
=
newActivityService
.
getRecommend2
(
"18583"
);
logger
.
info
(
"推荐位展示信息为"
+
response
.
asString
());
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验结果失败"
);
if
(
response
.
jsonPath
().
getString
(
"recommendQueueList[0].title"
).
contains
(
"测试"
)){
logger
.
info
(
"校验推荐位:title成功"
);
}
else
if
(
response
.
jsonPath
().
getString
(
"recommendQueueList[1].title"
).
contains
(
"测试"
)){
logger
.
info
(
"校验推荐位:title成功"
);
}
else
{
throw
new
Exception
(
"推荐位校验异常,请确认!"
);
}
//打开活动
HdResponse
=
developerService
.
openActivity
(
"18583"
,
"2239"
);
}
@Test
(
description
=
"数据后置清理"
,
priority
=
4
)
public
void
d_
删除活动
()
throws
Exception
{
//管理后台删除推荐位活动
managerService
.
delet
(
actId
);
}
}
\ No newline at end of file
src/test/java/http/cases/NewActivityTest/新活动工具测试_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
base.DuibaTestBase
;
import
http.service.Activity.ManagerService
;
import
http.service.Activity.NewActivityService
;
import
http.service.hd.ActivityService
;
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.Map
;
/**
* Created by zhaoran on 2018/1/2
*/
public
class
新活动工具测试
_DuibaTest
extends
DuibaTestBase
{
@Autowired
NewActivityService
newActivityService
;
@Autowired
ManagerService
managerService
;
@Autowired
ActivityService
activityService
;
private
static
DuibaLog
logger
=
DuibaLog
.
getLogger
();
@Test
public
void
福袋商品测试
()
throws
Exception
{
logger
.
info
(
"-------------------------------------活动中奖福袋商品-------------------------------------"
);
Response
response
=
this
.
新活动工具接口传参
(
"18567"
,
"1gffs6mq3"
,
"iOS"
);
//String type = String.valueOf(response.jsonPath().getString("lottery.type"));
//推啊出券系统检测
// 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=18567"
));
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.iosDownloadUrl"
).
contains
(
"//activity.tuiatest.cn/activity/redirect"
));
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
),
"11587"
,
"校验id失败"
);
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", "校验类型失败");
// }
}
@Test
public
void
谢谢参与转福袋测试
()
throws
Exception
{
logger
.
info
(
"-------------------------------------活动中奖谢谢参与转福袋-------------------------------------"
);
Response
response
=
this
.
新活动工具接口传参
(
"26640"
,
"1gffs6mq3"
,
"iOS"
);
//String type = String.valueOf(response.jsonPath().getString("lottery.type"));
//推啊出券系统检测
// if(activityService.isRunning("10.110.10.12","17791","tuia-engine")){
logger
.
info
(
"tuia-engine服务启动成功"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.isAppLucky"
),
"true"
,
"校验是否安慰奖失败"
);
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=26640"
));
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.iosDownloadUrl"
).
contains
(
"//activity.tuiatest.cn/activity/redirect"
));
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", "校验类型失败");
// }
}
@Test
public
void
免费次数测试
()
throws
Exception
{
Response
response1
=
newActivityService
.
ajaxElement
(
"3251"
,
"19114"
);
String
freeLimit
=
String
.
valueOf
(
response1
.
jsonPath
().
getString
(
"element.freeLimit"
));
logger
.
info
(
"抽奖前剩余免费抽奖次数:"
+
freeLimit
);
freeLimit
=
String
.
valueOf
(
Integer
.
valueOf
(
freeLimit
)-
1
);
Response
response
=
this
.
新活动工具接口传参
(
"19114"
,
"ogw24k6ns"
,
"iOS"
);
Thread
.
sleep
(
1000
);
Response
response2
=
newActivityService
.
ajaxElement
(
"3251"
,
"19114"
);
String
freeLimitNew
=
String
.
valueOf
(
response2
.
jsonPath
().
getString
(
"element.freeLimit"
));
logger
.
info
(
"抽奖后剩余免费抽奖次数:"
+
freeLimitNew
);
//校验比较,抽奖前后积分
Assert
.
assertEquals
(
freeLimitNew
,
freeLimit
);
logger
.
info
(
"校验抽奖前后剩余次数正确"
);
}
@Test
public
void
再抽一次测试
()
throws
Exception
{
//查询数据库,当前积分(抽奖扣积分流程校验)
Map
<
String
,
Object
>
mapuser
=
jdbc
.
findSimpleResult
(
"select * from dafuweng.user where id=2720"
);
String
credits
=
String
.
valueOf
(
mapuser
.
get
(
"credits"
));
logger
.
info
(
"抽奖前积分:"
+
credits
);
//扣去1积分
credits
=
String
.
valueOf
(
Integer
.
valueOf
(
credits
)-
1
);
//第一次抽奖
Response
response
=
this
.
新活动工具接口传参
(
"18580"
,
"m8rhchc"
,
"iOS"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.type"
),
"again"
,
"校验type失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
),
"11608"
,
"校验id失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"result"
),
"3"
,
"校验result失败"
);
logger
.
info
(
"校验:type,id,result成功"
);
//第一次抽奖后查询数据库,获取当前积分
mapuser
=
jdbc
.
findSimpleResult
(
"select * from dafuweng.user where id=2720"
);
String
creditsNew
=
String
.
valueOf
(
mapuser
.
get
(
"credits"
));
logger
.
info
(
"第一次抽奖后积分:"
+
creditsNew
);
//校验比较,抽奖前后积分
Assert
.
assertEquals
(
credits
,
creditsNew
);
logger
.
info
(
"校验第一次抽奖前后积分正确"
);
//第二次抽奖
response
=
newActivityService
.
doJoin2
(
"18580"
,
"m8rhchc"
,
response
.
jsonPath
().
getString
(
"againTag"
));
response
.
prettyPrint
();
Thread
.
sleep
(
2000
);
//第二次抽奖后查询数据库,获取当前积分
mapuser
=
jdbc
.
findSimpleResult
(
"select * from dafuweng.user where id=2720"
);
String
creditsNew2
=
String
.
valueOf
(
mapuser
.
get
(
"credits"
));
logger
.
info
(
"第二次抽奖后积分:"
+
creditsNew2
);
//校验比较,抽奖前后积分
Assert
.
assertEquals
(
creditsNew
,
creditsNew2
);
logger
.
info
(
"校验第二次抽奖前后积分正确"
);
}
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
=
30
;
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
;
}
/**
* 提供精确的减法运算。
* @param v1 被减数
* @param v2 减数
* @return 两个参数的差
*/
public
static
double
sub
(
double
v1
,
double
v2
){
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
subtract
(
b2
).
doubleValue
();
}
}
\ No newline at end of file
src/test/java/http/cases/NewActivityTest/无积分测试_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
base.DuibaTestBase
;
import
http.service.Activity.ManagerService
;
import
http.service.Activity.NewActivityService
;
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.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 zhaoran on 2018/1/2
*/
public
class
无积分测试
_DuibaTest
extends
DuibaTestBase
{
@Autowired
NewActivityService
newActivityService
;
@Autowired
ManagerService
managerService
;
@Autowired
Authorization
authorization
;
private
static
DuibaLog
logger
=
DuibaLog
.
getLogger
();
private
String
url
=
"http://activity.m.duibatest.com.cn"
;
@DataProvider
public
Object
[][]
providerMethod
(
Method
method
){
Object
[][]
result
=
null
;
if
(
method
.
getName
().
equals
(
"参与次数测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
1
,
"5243"
,
"23105"
,
"永久限制5次,不免费"
},
new
Object
[]{
2
,
"5314"
,
"23314"
,
"无限制,不免费"
},
new
Object
[]{
3
,
"5315"
,
"23315"
,
"无限制,每天免费999"
},
};
}
return
result
;
}
@Test
(
dataProvider
=
"providerMethod"
)
public
void
参与次数测试
(
int
casenum
,
String
hdToolId
,
String
activityId
,
String
casename
)
throws
Exception
{
logger
.
info
(
"-------------------------------------"
+
casename
+
"-------------------------------------"
);
//校验ajax接口关键字段返回
logger
.
info
(
"请求/hdtool/ajaxElement接口"
);
Response
response_ajax
=
this
.
ajaxElement
(
hdToolId
,
activityId
);
Assert
.
assertEquals
(
response_ajax
.
jsonPath
().
getString
(
"element.isCreditsTypeOpen"
),
"true"
,
"校验isCreditsTypeOpen失败"
);
logger
.
info
(
"请求/hdtool/doJoin接口"
);
Response
response
=
this
.
doJoin
(
activityId
);
response
.
prettyPrint
();
//根据case选择对应的校验项
switch
(
casenum
){
case
1
:
Assert
.
assertEquals
(
response_ajax
.
jsonPath
().
getString
(
"element.status"
),
"4"
,
"校验status失败"
);
logger
.
info
(
"ajax校验项:status成功"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"message"
),
"永久次数已用完"
,
"校验message失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"status"
),
"3"
,
"校验status失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"false"
,
"校验success失败"
);
logger
.
info
(
"doJoin校验项:message,status,success成功"
);
break
;
case
2
:
Assert
.
assertEquals
(
response_ajax
.
jsonPath
().
getString
(
"element.status"
),
"3"
,
"校验status失败"
);
logger
.
info
(
"ajax校验项:status成功"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"message"
),
"今日次数已用完"
,
"校验message失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"status"
),
"3"
,
"校验status失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"false"
,
"校验success失败"
);
logger
.
info
(
"doJoin校验项:message,status,success成功"
);
break
;
case
3
:
Assert
.
assertEquals
(
response_ajax
.
jsonPath
().
getString
(
"element.status"
),
"5"
,
"校验status失败"
);
logger
.
info
(
"ajax校验项:status成功"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"needCredits"
),
"0"
,
"校验needCredits失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验success失败"
);
logger
.
info
(
"doJoin校验项:needCredits,success成功"
);
break
;
}
//切换回2720用户
authorization
.
dafuwengLogin
(
2720
,
true
);
}
public
Response
ajaxElement
(
String
hdToolId
,
String
activityId
)
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"hdType"
,
"duiba"
);
map
.
put
(
"hdToolId"
,
hdToolId
);
map
.
put
(
"preview"
,
"false"
);
map
.
put
(
"actId"
,
activityId
);
logger
.
info
(
"请求/hdtool/ajaxElement接口"
);
Response
response_ajax
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
2723
,
true
)).
params
(
map
).
post
(
url
+
"/hdtool/ajaxElement"
);
try
{
Assert
.
assertEquals
(
response_ajax
.
jsonPath
().
getString
(
"success"
),
"true"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"/hdtool/ajaxElement接口失败,返回信息:"
+
response_ajax
.
asString
());
}
catch
(
Error
er
){
throw
new
Exception
(
"/hdtool/ajaxElement接口失败,返回信息:"
+
response_ajax
.
asString
());
}
return
response_ajax
;
}
public
Response
doJoin
(
String
activityId
)
throws
Exception
{
Map
<
String
,
String
>
map2
=
new
HashMap
<>();
map2
.
put
(
"activityId"
,
activityId
);
map2
.
put
(
"token"
,
"1hrja7"
);
logger
.
info
(
"请求/hdtool/ajaxElement接口"
);
Response
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
2723
)).
params
(
map2
).
post
(
url
+
"/hdtool/doJoin"
);
return
response
;
}
}
\ No newline at end of file
src/test/java/http/cases/NewActivityTest/谢谢参与测试_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
base.DuibaTestBase
;
import
http.service.Activity.ManagerService
;
import
http.service.Activity.NewActivityService
;
import
http.service.hd.ActivityService
;
import
base.DuibaLog
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.Test
;
/**
* Created by zhaoran on 2018/10/25
*/
public
class
谢谢参与测试
_DuibaTest
extends
DuibaTestBase
{
@Autowired
NewActivityService
newActivityService
;
@Autowired
ManagerService
managerService
;
@Autowired
ActivityService
activityService
;
private
static
DuibaLog
logger
=
DuibaLog
.
getLogger
();
private
static
Integer
uid
=
3661
;
@Test
public
void
谢谢参与测试
()
throws
Exception
{
logger
.
info
(
"-------------------------------------活动中奖谢谢参与-------------------------------------"
);
Response
response
=
this
.
新活动工具接口传参
(
uid
,
"34514"
,
"1gffs6mq3"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.type"
),
"thanks"
,
"校验类型失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
).
isEmpty
(),
false
,
"校验id失败"
);
//校验返回字段
Assert
.
assertEquals
(
response
.
asString
().
contains
(
"id"
),
true
,
"校验id失败"
);
logger
.
info
(
"校验type,id成功"
);
}
public
Response
新活动工具接口传参
(
int
uid
,
String
activityId
,
String
token
)
throws
Exception
{
Response
response
=
newActivityService
.
doJoin2
(
uid
,
activityId
,
token
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
response
=
newActivityService
.
getOrderStatus2
(
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
=
newActivityService
.
getOrderStatus2
(
uid
,
orderId
);
result
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"result"
));
i
--;
response
.
prettyPrint
();
}
return
response
;
}
}
\ No newline at end of file
src/test/java/http/cases/NewActivityTest/闯关活动测试_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
base.DuibaTestBase
;
import
http.service.Activity.NewActivityService
;
import
utils.MatcherString
;
import
base.DuibaLog
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.Test
;
/**
* Created by zhaoran on 2018/3/15
*/
public
class
闯关活动测试
_DuibaTest
extends
DuibaTestBase
{
@Autowired
NewActivityService
newActivityService
;
private
static
DuibaLog
logger
=
DuibaLog
.
getLogger
();
@Test
(
description
=
"闯关步数计算校验"
)
public
void
闯关步数测试
()
throws
Exception
{
Response
response
=
newActivityService
.
ajaxElement
(
"5106"
,
"22706"
);
String
throughCurrentStep
=
response
.
jsonPath
().
getString
(
"throughCurrentStep"
);
logger
.
info
(
"摇骰前位置为:"
+
throughCurrentStep
);
//摇骰子
response
=
newActivityService
.
doJoin2
(
"22706"
,
"efctd"
);
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
response
=
newActivityService
.
throughSubmit
(
orderId
);
//获取点数
String
point
=
response
.
jsonPath
().
getString
(
"point"
);
logger
.
info
(
"摇骰点数为:"
+
point
);
String
forward
=
MatcherString
.
getString
(
response
.
asString
(),
"forward\":(.*?),"
,
1
);
logger
.
info
(
"前进步数为:"
+
forward
);
String
retreat
=
MatcherString
.
getString
(
response
.
asString
(),
"retreat\":(.*?),"
,
1
);
logger
.
info
(
"后退步数为:"
+
retreat
);
//获取当前位置
String
currentLocation
=
response
.
jsonPath
().
getString
(
"currentLocation"
);
logger
.
info
(
"摇骰后位置为:"
+
currentLocation
);
if
(!
forward
.
equals
(
""
)){
int
step
=
Integer
.
valueOf
(
throughCurrentStep
)
+
Integer
.
valueOf
(
point
)
+
Integer
.
valueOf
(
forward
);
if
(
step
>
20
){
step
=
step
-
20
;
String
expStep
=
String
.
valueOf
(
step
);
logger
.
info
(
"预期摇骰后位置为:"
+
expStep
);
Assert
.
assertEquals
(
currentLocation
,
expStep
,
"闯关步数校验成功"
);
}
else
{
String
expStep
=
String
.
valueOf
(
step
);
logger
.
info
(
"预期摇骰后位置为:"
+
expStep
);
Assert
.
assertEquals
(
currentLocation
,
expStep
,
"闯关步数校验成功"
);
}
}
else
if
(!
retreat
.
equals
(
""
)){
String
expStep
=
String
.
valueOf
(
Integer
.
valueOf
(
throughCurrentStep
)
+
Integer
.
valueOf
(
point
)
-
Integer
.
valueOf
(
retreat
));
logger
.
info
(
"预期摇骰后位置为:"
+
expStep
);
Assert
.
assertEquals
(
currentLocation
,
expStep
,
"闯关步数校验成功"
);
}
else
{
int
step
=
Integer
.
valueOf
(
throughCurrentStep
)
+
Integer
.
valueOf
(
point
);
if
(
step
>
20
){
step
=
step
-
20
;
String
expStep
=
String
.
valueOf
(
step
);
logger
.
info
(
"预期摇骰后位置为:"
+
expStep
);
Assert
.
assertEquals
(
currentLocation
,
expStep
,
"闯关步数校验成功"
);
}
else
{
String
expStep
=
String
.
valueOf
(
step
);
logger
.
info
(
"预期摇骰后位置为:"
+
expStep
);
Assert
.
assertEquals
(
currentLocation
,
expStep
,
"闯关步数校验成功"
);
}
}
}
}
src/test/java/http/cases/NewActivityTest/页面元素测试_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
base.Config
;
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.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
;
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
,
"27129"
,
"奖品—优惠券详情校验"
},
new
Object
[]{
2
,
"27131"
,
"奖品—实物详情校验"
},};
}
return
result
;
}
@Test
(
description
=
"校验接口返回的自定义规则概率文案"
)
public
void
文案接口测试
()
throws
Exception
{
Response
response
=
newActivityService
.
getHdtoolConfig
(
"19204"
,
"3347"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"userConfig[1].childrens[1].value"
),
"<h3>活动说明</h3><p>这里是活动说明</p>"
,
"校验显示活动说明失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"userConfig[1].childrens[2].value"
),
"这里是活动规则"
,
"校验显示活动规则失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"userConfig[1].childrens[3].value"
),
"<p>这里是中奖概率说明</p>"
,
"校验显示活动概率失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"userConfig[0].childrens[0].value"
),
"//yun.dui88.com/images/201806/5u2hsakdun.jpg"
,
"校验自定义图片上传失败"
);
logger
.
info
(
"接口文案显示正确!"
);
}
@Test
(
description
=
"校验接口返回的奖品"
)
public
void
奖品显示测试
()
throws
Exception
{
Response
response
=
newActivityService
.
ajaxElement
(
"duiba"
,
"3347"
,
"19204"
,
"false"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[0].prizeType"
),
"thanks"
,
"校验显示谢谢参与失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[1].prizeType"
),
"coupon"
,
"校验显示优惠券失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[2].prizeType"
),
"object"
,
"校验显示实物失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[3].prizeType"
),
"alipay"
,
"校验显示支付宝失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[4].prizeType"
),
"qb"
,
"校验显示Q币失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[5].prizeType"
),
"phonebill"
,
"校验显示话费失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[6].prizeType"
),
"collectGoods"
,
"校验显示集卡失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[7].prizeType"
),
"virtual"
,
"校验显示虚拟奖失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[0].hidden"
),
"false"
,
"校验是否显示谢谢参与失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[1].hidden"
),
"false"
,
"校验是否显示优惠券失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[2].hidden"
),
"false"
,
"校验是否显示实物失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[3].hidden"
),
"false"
,
"校验是否显示支付宝失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[4].hidden"
),
"false"
,
"校验是否显示Q币失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[5].hidden"
),
"false"
,
"校验是否显示话费失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[6].hidden"
),
"false"
,
"校验是否显示集卡失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"options[7].hidden"
),
"false"
,
"校验是否显示虚拟奖失败"
);
logger
.
info
(
"奖品显示正确!"
);
}
@Test
(
dataProvider
=
"providerMethod"
)
public
void
奖品详情测试
(
int
casenum
,
String
itemId
,
String
casename
)
throws
Exception
{
logger
.
info
(
"-------------------------------------"
+
casename
+
"-------------------------------------"
);
Response
response
=
newActivityService
.
prizeDetail
(
itemId
);
switch
(
casenum
){
case
1
:
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"description"
),
"优惠券详情"
,
"校验显示详情失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"title"
),
"【勿动】自动化优惠券——兑换记录页"
,
"校验显示title失败"
);
break
;
case
2
:
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"description"
),
"实物详情<br>"
,
"校验显示详情失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"title"
),
"【勿动】自动化实物奖品"
,
"校验显示title失败"
);
break
;
}
logger
.
info
(
"校验链接券码项:openUrl,useBtnText成功"
);
}
}
src/test/java/http/cases/NewActivityTest/领奖流程测试_DuibaTest.java
0 → 100644
View file @
af48a38c
package
http
.
cases
.
NewActivityTest
;
import
base.DuibaTestBase
;
import
http.service.Activity.ManagerService
;
import
http.service.Activity.NewActivityService
;
import
http.service.hd.ActivityService
;
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.DataProvider
;
import
org.testng.annotations.Test
;
import
java.io.IOException
;
import
java.lang.reflect.Method
;
import
java.math.BigDecimal
;
import
java.util.Iterator
;
import
java.util.Map
;
/**
* Created by zhaoran on 2018/1/2
*/
public
class
领奖流程测试
_DuibaTest
extends
DuibaTestBase
{
@Autowired
NewActivityService
newActivityService
;
@Autowired
ManagerService
managerService
;
@Autowired
ActivityService
activityService
;
private
static
DuibaLog
logger
=
DuibaLog
.
getLogger
();
//指定用户
private
static
int
uid
=
3742
;
@DataProvider
public
Iterator
<
Object
[]>
providerMethod
(
Method
method
)
throws
IOException
{
Iterator
<
Object
[]>
result
=
null
;
if
(
method
.
getName
().
equals
(
"领奖流程测试"
))
{
result
=
new
ExcelDataProvider
(
"duiba/中奖领奖数据"
);
}
return
result
;
}
@Test
(
dataProvider
=
"providerMethod"
)
public
void
领奖流程测试
(
Map
<
String
,
String
>
data
)
throws
Exception
{
logger
.
info
(
"-------------------------------------"
+
data
.
get
(
"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
);
//获取当前兑吧余额
Response
responses
=
managerService
.
adminDuibaBalance
();
String
balance
=
MatcherString
.
getString
(
responses
.
asString
(),
"type=\"hidden\" value=\"(.*?)\""
,
1
);
logger
.
info
(
"抽奖前余额:"
+
balance
);
//进行接口测试传参
Response
response
=
this
.
新活动工具接口传参
(
data
.
get
(
"activityId"
),
data
.
get
(
"token"
));
logger
.
info
(
"hdtool/getOrderStatus接口,返回信息:"
+
response
.
asString
());
String
type
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"lottery.type"
));
//根据case选择校验项
if
(
type
.
equals
(
"phonebill"
)){
//balance = String.valueOf(sub(Double.valueOf(balance),10.08));
balance
=
String
.
format
(
"%.2f"
,
sub
(
Double
.
valueOf
(
balance
),
10.08
));
logger
.
info
(
"计算后的预期余额:"
+
balance
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.title"
),
"话费"
,
"校验title失败"
);
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.link"
).
contains
(
"/activity/takePrizeNew?recordId="
));
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
),
"11599"
,
"校验id失败"
);
logger
.
info
(
"校验:title,link,id成功"
);
}
if
(
type
.
equals
(
"alipay"
)){
//balance = String.valueOf(sub(Double.valueOf(balance),1.02));
balance
=
String
.
format
(
"%.2f"
,
sub
(
Double
.
valueOf
(
balance
),
1.02
));
logger
.
info
(
"计算后的预期余额:"
+
balance
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.title"
),
"支付宝"
,
"校验title失败"
);
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.link"
).
contains
(
"/activity/takePrizeNew?recordId="
));
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
),
"11602"
,
"校验id失败"
);
logger
.
info
(
"校验:title,link,id成功"
);
}
if
(
type
.
equals
(
"qb"
)){
balance
=
String
.
format
(
"%.2f"
,
sub
(
Double
.
valueOf
(
balance
),
0.96
));
logger
.
info
(
"计算后的预期余额:"
+
balance
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.title"
),
"1Q币"
,
"校验title失败"
);
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.link"
).
contains
(
"/activity/takePrizeNew?recordId="
));
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
),
"21778"
,
"校验id失败"
);
logger
.
info
(
"校验:title,link,id成功"
);
}
if
(
type
.
equals
(
"object"
)){
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.title"
),
"实物奖品"
,
"校验title失败"
);
Assert
.
assertTrue
(
response
.
jsonPath
().
getString
(
"lottery.link"
).
contains
(
"/activity/takePrizeNew?recordId="
));
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"lottery.id"
),
"11604"
,
"校验id失败"
);
logger
.
info
(
"校验:link,link,id成功"
);
}
//查询数据库,获取当前积分
Thread
.
sleep
(
3000
);
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
(
"校验领奖前后积分正确"
);
//校验user表积分与consumer表积分是否相同
// mapuser = jdbc.findSimpleResult("select * from new_consumer.consumer_0010 where id=100025007");
// String creditsCon = String.valueOf(mapuser.get("credits"));
// logger.info("consumer表用户抽奖后积分:"+creditsCon);
// Assert.assertEquals(creditsNew,creditsCon);
// logger.info("校验user表与consumer表领奖后积分一致");
//领奖流程
String
recordId
=
MatcherString
.
getString
(
response
.
asString
(),
"recordId=(.*?)&"
,
1
);
response
=
newActivityService
.
doTakePrize
(
uid
,
type
,
recordId
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"message"
),
"领奖成功"
);
logger
.
info
(
"结果:"
+
type
+
"领奖流程成功"
);
//校验兑吧余额
if
(!
type
.
equals
(
"object"
))
{
Thread
.
sleep
(
5000
);
responses
=
managerService
.
adminDuibaBalance
();
String
Newbalance
=
MatcherString
.
getString
(
responses
.
asString
(),
"type=\"hidden\" value=\"(.*?)\""
,
1
);
logger
.
info
(
"领奖后余额:"
+
Newbalance
);
Assert
.
assertEquals
(
Newbalance
,
balance
);
logger
.
info
(
"校验抽奖前后兑吧余额正确"
);
}
}
public
Response
新活动工具接口传参
(
String
activityId
,
String
token
)
throws
Exception
{
Response
response
=
newActivityService
.
doJoin2
(
uid
,
activityId
,
token
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
response
=
newActivityService
.
getOrderStatus21
(
orderId
,
uid
);
response
.
prettyPrint
();
String
result
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"result"
));
int
i
=
30
;
while
(
i
>
0
&&(
result
.
equals
(
"0"
))){
Thread
.
sleep
(
1000
);
response
=
newActivityService
.
getOrderStatus21
(
orderId
,
uid
);
result
=
String
.
valueOf
(
response
.
jsonPath
().
getString
(
"result"
));
i
--;
response
.
prettyPrint
();
}
return
response
;
}
/**
* 提供精确的减法运算。
* @param v1 被减数
* @param v2 减数
* @return 两个参数的差
*/
public
static
double
sub
(
double
v1
,
double
v2
){
BigDecimal
b1
=
new
BigDecimal
(
Double
.
toString
(
v1
));
BigDecimal
b2
=
new
BigDecimal
(
Double
.
toString
(
v2
));
return
b1
.
subtract
(
b2
).
doubleValue
();
}
}
\ No newline at end of file
src/test/java/http/service/app/ConfirmService.java
View file @
af48a38c
package
http
.
service
.
app
;
import
com.duiba.qa.duiba
.service.Authorization
;
import
com.duiba.qa.publics.util
.DuibaLog
;
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
;
...
...
src/test/java/http/service/app/CouponExchangeService.java
View file @
af48a38c
package
http
.
service
.
app
;
import
com.duiba.qa.duiba
.service.Authorization
;
import
com.duiba.qa.publics.util
.DuibaLog
;
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
;
...
...
src/test/java/http/service/app/SeckillService.java
View file @
af48a38c
...
...
@@ -2,9 +2,9 @@ package http.service.app;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.duiba.qa.duiba
.service.Authorization
;
import
com.duiba.qa.duiba.
utils.MatcherString
;
import
com.duiba.qa.publics.util
.DuibaLog
;
import
http
.service.Authorization
;
import
utils.MatcherString
;
import
base
.DuibaLog
;
import
io.restassured.http.Cookies
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
src/test/java/http/service/app/VirtualExchangeService.java
View file @
af48a38c
package
http
.
service
.
app
;
import
com.duiba.qa.publics.util
.DuibaLog
;
import
base
.DuibaLog
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
...
...
src/test/java/http/service/hd/CustomHdToolCtrlService.java
View file @
af48a38c
package
http
.
service
.
hd
;
import
com.duiba.qa.duiba
.enums.ActivityDataTypeEnum
;
import
com.duiba.qa.duiba
.model.CustomHdToolVO
;
import
com.duiba.qa.duiba
.service.Authorization
;
import
com.duiba.qa.publics.util
.DuibaLog
;
import
http
.enums.ActivityDataTypeEnum
;
import
http
.model.CustomHdToolVO
;
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
;
...
...
src/test/java/http/service/hd/DevFloorService.java
View file @
af48a38c
package
http
.
service
.
hd
;
import
com.duiba.qa.duiba
.service.Authorization
;
import
com.duiba.qa.publics.util
.DuibaLog
;
import
http
.service.Authorization
;
import
base
.DuibaLog
;
import
io.restassured.http.ContentType
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
src/test/java/http/service/hd/DevItemService.java
View file @
af48a38c
package
http
.
service
.
hd
;
import
com.duiba.qa.publics.util
.DuibaLog
;
import
base
.DuibaLog
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
...
...
src/test/java/http/service/hd/DevSkinService.java
View file @
af48a38c
package
http
.
service
.
hd
;
import
com.alibaba.fastjson.JSONObject
;
import
com.duiba.qa.publics.util
.DuibaLog
;
import
base
.DuibaLog
;
import
io.restassured.http.ContentType
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
src/test/java/http/service/hd/DeveloperService.java
View file @
af48a38c
package
http
.
service
.
hd
;
import
com.alibaba.fastjson.JSON
;
import
com.duiba.qa.duiba
.service.Authorization
;
import
com.duiba.qa.publics.util
.DuibaLog
;
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
;
...
...
src/test/java/http/service/hd/DsOrderService.java
View file @
af48a38c
package
http
.
service
.
hd
;
import
com.duiba.qa.duiba
.service.Authorization
;
import
com.duiba.qa.publics.util
.DuibaLog
;
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
;
...
...
src/test/java/utils/ExcelDataProvider.java
0 → 100644
View file @
af48a38c
package
utils
;
import
jxl.Cell
;
import
jxl.Sheet
;
import
jxl.Workbook
;
import
org.testng.Assert
;
import
java.io.FileInputStream
;
import
java.io.InputStream
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
/**
* Excel放在Data文件夹下
* Excel命名方式:测试类名.xls
* Excel的sheet命名方式:测试方法名
* Excel第一行为Map键值
* @ClassName: ExcelDataProvider
*/
public
class
ExcelDataProvider
implements
Iterator
<
Object
[]>
{
private
Workbook
book
=
null
;
private
Sheet
sheet
=
null
;
private
int
rowNum
=
0
;
private
int
currentRowNo
=
0
;
private
int
columnNum
=
0
;
private
String
[]
columnnName
;
public
ExcelDataProvider
(
String
classname
){
this
(
classname
,
null
);
}
public
ExcelDataProvider
(
String
classname
,
String
methodname
)
{
try
{
int
dotNum
=
classname
.
indexOf
(
"."
);
if
(
dotNum
>
0
)
{
classname
=
classname
.
substring
(
classname
.
lastIndexOf
(
"."
)
+
1
,
classname
.
length
());
}
String
path
=
"data/"
+
classname
+
".xls"
;
System
.
out
.
println
(
path
);
InputStream
inputStream
=
new
FileInputStream
(
path
);
book
=
Workbook
.
getWorkbook
(
inputStream
);
sheet
=
book
.
getSheet
(
0
);
//按方法名取不到sheet,就取第一个sheet
if
(
null
==
sheet
){
sheet
=
book
.
getSheet
(
0
);
}
rowNum
=
sheet
.
getRows
();
Cell
[]
cell
=
sheet
.
getRow
(
0
);
columnNum
=
cell
.
length
;
columnnName
=
new
String
[
cell
.
length
];
for
(
int
i
=
0
;
i
<
cell
.
length
;
i
++)
{
columnnName
[
i
]
=
cell
[
i
].
getContents
().
toString
();
}
this
.
currentRowNo
++;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
Assert
.
fail
(
"unable to read Excel data"
);
}
}
public
boolean
hasNext
()
{
if
(
this
.
rowNum
==
0
||
this
.
currentRowNo
>=
this
.
rowNum
)
{
try
{
book
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
else
{
Cell
[]
cells
=
null
;
// sheet下一行内容为空判定结束
try
{
cells
=
sheet
.
getRow
(
currentRowNo
);
}
catch
(
Exception
e
){
return
false
;
}
if
(
cells
==
null
||
cells
[
0
]==
null
||
cells
[
0
].
getContents
().
trim
().
length
()<=
0
)
return
false
;
return
true
;
}
}
public
Object
[]
next
()
{
Cell
[]
c
=
sheet
.
getRow
(
this
.
currentRowNo
);
Map
<
String
,
String
>
data
=
new
HashMap
<
String
,
String
>();
// List<String> list = new ArrayList<String>();
for
(
int
i
=
0
;
i
<
this
.
columnNum
;
i
++)
{
String
temp
=
""
;
try
{
temp
=
c
[
i
].
getContents
().
toString
();
}
catch
(
ArrayIndexOutOfBoundsException
ex
)
{
temp
=
""
;
}
// if(temp != null&& !temp.equals(""))
// list.add(temp);
data
.
put
(
this
.
columnnName
[
i
],
temp
);
}
Object
object
[]
=
new
Object
[
1
];
object
[
0
]
=
data
;
this
.
currentRowNo
++;
return
object
;
}
public
void
remove
()
{
throw
new
UnsupportedOperationException
(
"remove unsupported."
);
}
public
void
setCurrentRowNo
(
int
currentRowNo
)
{
this
.
currentRowNo
=
currentRowNo
;
}
public
int
getCurrentRowNo
()
{
return
currentRowNo
;
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment