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
ecaac2d5
Commit
ecaac2d5
authored
Mar 29, 2019
by
赵然
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of gitlab2.dui88.com:mabo/test-platform
parents
399aed5e
a5827141
Changes
27
Show whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
5316 additions
and
111 deletions
+5316
-111
pom.xml
pom.xml
+1
-1
DingdingResult.java
src/test/java/base/DingdingResult.java
+10
-2
DuibaBase.java
src/test/java/base/DuibaBase.java
+11
-0
GitlabUtils.java
src/test/java/base/GitlabUtils.java
+3
-5
CheckTemplet.java
src/test/java/http/cases/ExchangeTest/CheckTemplet.java
+10
-4
Database.java
src/test/java/http/cases/ExchangeTest/Database.java
+4
-0
兑吧卡密_兑换流程测试_ExchangeTest.java
...ava/http/cases/ExchangeTest/兑吧卡密_兑换流程测试_ExchangeTest.java
+464
-0
兑吧新优惠券_兑换流程测试_ExchangeTest.java
...a/http/cases/ExchangeTest/兑吧新优惠券_兑换流程测试_ExchangeTest.java
+495
-0
兑吧新实物_兑换流程测试_ExchangeTest.java
...va/http/cases/ExchangeTest/兑吧新实物_兑换流程测试_ExchangeTest.java
+356
-4
兑吧老优惠券_兑换流程测试_ExchangeTest.java
...a/http/cases/ExchangeTest/兑吧老优惠券_兑换流程测试_ExchangeTest.java
+0
-53
多档位话费_兑换流程测试_ExchangeTest.java
...va/http/cases/ExchangeTest/多档位话费_兑换流程测试_ExchangeTest.java
+1
-1
自有新优惠券_兑换限制测试.java
...java/http/cases/ExchangeTest/自有_商品兑换限制/自有新优惠券_兑换限制测试.java
+429
-0
自有新卡密_兑换限制测试.java
.../java/http/cases/ExchangeTest/自有_商品兑换限制/自有新卡密_兑换限制测试.java
+438
-0
自有新虚拟商品_充值_兑换限制.java
...va/http/cases/ExchangeTest/自有_商品兑换限制/自有新虚拟商品_充值_兑换限制.java
+428
-0
自有老优惠券商品_兑换限制测试.java
...va/http/cases/ExchangeTest/自有_商品兑换限制/自有老优惠券商品_兑换限制测试.java
+438
-0
自有老实物_兑换限制测试.java
.../java/http/cases/ExchangeTest/自有_商品兑换限制/自有老实物_兑换限制测试.java
+435
-0
自有老虚拟商品_兑换限制测试.java
...ava/http/cases/ExchangeTest/自有_商品兑换限制/自有老虚拟商品_兑换限制测试.java
+436
-0
秒杀自有老优惠券_兑换限制_SeckillTest.java
...ava/http/cases/SeckillTest/秒杀自有老优惠券_兑换限制_SeckillTest.java
+250
-0
秒杀自有老实物_兑换限制.java
src/test/java/http/cases/SeckillTest/秒杀自有老实物_兑换限制.java
+0
-41
秒杀自有老实物_兑换限制_SeckillTest.java
...java/http/cases/SeckillTest/秒杀自有老实物_兑换限制_SeckillTest.java
+205
-0
秒杀自有老虚拟商品_兑换限制_SeckillTest.java
...va/http/cases/SeckillTest/秒杀自有老虚拟商品_兑换限制_SeckillTest.java
+227
-0
秒杀话费_兑换限制_SeckillTest.java
...st/java/http/cases/SeckillTest/秒杀话费_兑换限制_SeckillTest.java
+280
-0
Authorization.java
src/test/java/http/service/Authorization.java
+9
-0
CouponExchangeService.java
src/test/java/http/service/app/CouponExchangeService.java
+31
-0
SeckillService.java
src/test/java/http/service/app/SeckillService.java
+125
-0
gawService.java
src/test/java/http/service/app/gawService.java
+227
-0
DsOrderService.java
src/test/java/http/service/hd/DsOrderService.java
+3
-0
No files found.
pom.xml
View file @
ecaac2d5
...
...
@@ -65,7 +65,7 @@
<dependency>
<groupId>
io.rest-assured
</groupId>
<artifactId>
rest-assured
</artifactId>
<version>
3.
0.3
</version>
<version>
3.
3.0
</version>
<scope>
test
</scope>
</dependency>
...
...
src/test/java/base/DingdingResult.java
View file @
ecaac2d5
...
...
@@ -7,6 +7,7 @@ import org.springframework.context.ApplicationContext;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.core.env.Environment
;
import
java.io.FileNotFoundException
;
import
java.io.UnsupportedEncodingException
;
import
java.util.*
;
...
...
@@ -62,8 +63,14 @@ public class DingdingResult {
changes
=
Postman
.
sendFindTestApp
(
params
);
}
try
{
gitlabProjectMerges
=
GitlabUtils
.
getMessage
(
"credits-group"
,
changes
);
changes
=
changes
+
" 提交者:"
+
gitlabProjectMerges
.
getAuthor
().
getName
()+
" 描述:"
+
gitlabProjectMerges
.
getDescription
();
}
catch
(
Exception
e
){
logger
.
info
(
"不是兑吧服务,未发现变革"
);
}
this
.
total
=
total
;
...
...
@@ -125,6 +132,7 @@ public class DingdingResult {
// System.out.println(e);
// }
if
(
gitlabProjectMerges
!=
null
)
names
.
add
(
gitlabProjectMerges
.
getAuthor
().
getUsername
());
}
else
{
...
...
src/test/java/base/DuibaBase.java
View file @
ecaac2d5
package
base
;
import
io.restassured.RestAssured
;
import
org.apache.http.client.params.ClientPNames
;
import
org.apache.http.params.CoreConnectionPNames
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.testng.AbstractTestNGSpringContextTests
;
...
...
@@ -8,6 +11,9 @@ import org.testng.annotations.BeforeSuite;
import
javax.annotation.PostConstruct
;
import
static
io
.
restassured
.
RestAssured
.
config
;
import
static
io
.
restassured
.
config
.
HttpClientConfig
.
httpClientConfig
;
/**
* Created by mabo on 2018/9/20
*/
...
...
@@ -25,6 +31,11 @@ public class DuibaBase extends AbstractTestNGSpringContextTestsDuiba {
logger
.
info
(
"--------------------DuibaBase.setUp() Tests"
);
//只初始化一次
jdbc
.
initDataSource
();
//设置接口响应超时时间
RestAssured
.
config
=
RestAssured
.
config
().
httpClient
(
httpClientConfig
()
.
setParam
(
ClientPNames
.
CONN_MANAGER_TIMEOUT
,
Long
.
valueOf
(
5000
))
// HttpConnectionManager connection return time
.
setParam
(
CoreConnectionPNames
.
CONNECTION_TIMEOUT
,
5000
)
// Remote host connection time
.
setParam
(
CoreConnectionPNames
.
SO_TIMEOUT
,
10000
));
// Remote host response time
}
...
...
src/test/java/base/GitlabUtils.java
View file @
ecaac2d5
...
...
@@ -14,15 +14,13 @@ import java.util.List;
public
class
GitlabUtils
{
public
static
final
String
GIT_URL
=
"http://gitlab2.dui88.com"
;
public
static
final
String
SECRET
=
"rCyBy1sQ-JckquyFmo4c"
;
public
static
GitlabProjectMerges
getMessage
(
String
namespace
,
String
projectname
){
public
static
GitlabProjectMerges
getMessage
(
String
namespace
,
String
projectname
)
throws
IOException
{
GitlabAPI
gitlabAPI
=
GitlabAPI
.
connect
(
GitlabUtils
.
GIT_URL
,
GitlabUtils
.
SECRET
);
GitlabProject
gitlabProject
=
null
;
try
{
gitlabProject
=
gitlabAPI
.
getProject
(
namespace
,
projectname
);
// gitlabProject = gitlabAPI.getProject("credits-group","hdtool-web");
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
GitabProjectLatelyChangeQry
qry
=
new
GitabProjectLatelyChangeQry
();
qry
.
setId
(
gitlabProject
.
getId
());
...
...
src/test/java/http/cases/ExchangeTest/CheckTemplet.java
View file @
ecaac2d5
...
...
@@ -18,10 +18,16 @@ public class CheckTemplet extends DuibaBase {
@BeforeSuite
public
void
setTemplet
()
throws
Exception
{
try
{
logger
.
info
(
"------------------------setTemplet()"
);
this
.
setVirtual
();
Thread
.
sleep
(
1000
);
this
.
setQb
();
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
}
public
void
setVirtual
()
throws
Exception
{
...
...
src/test/java/http/cases/ExchangeTest/Database.java
View file @
ecaac2d5
...
...
@@ -14,4 +14,8 @@ public class Database {
public
static
String
orders7
=
"orders_0211"
;
public
static
String
orders8
=
"orders_0090"
;
public
static
String
orders9
=
"orders_0203"
;
public
static
String
orders10
=
"orders_0411"
;
public
static
String
orders11
=
"orders_0182"
;
}
src/test/java/http/cases/ExchangeTest/兑吧卡密_兑换流程测试_ExchangeTest.java
0 → 100644
View file @
ecaac2d5
package
http
.
cases
.
ExchangeTest
;
import
base.DuibaBase
;
import
base.DuibaBases
;
import
http.service.Activity.ManagerService
;
import
http.service.Authorization
;
import
http.service.app.MobileService
;
import
http.service.app.gawService
;
import
http.service.app.tawService
;
import
http.service.hd.DeveloperAccountService
;
import
http.service.hd.DappConfigService
;
import
org.apache.logging.log4j.core.pattern.AbstractStyleNameConverter
;
import
org.testng.annotations.AfterClass
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.DataProvider
;
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
;
import
java.lang.reflect.Method
;
import
java.util.HashMap
;
import
java.util.Map
;
import
utils.RedisUtil
;
import
static
io
.
restassured
.
RestAssured
.
given
;
/**
* Created by lvwenyan on 2019/3/26.
*/
public
class
兑吧卡密
_
兑换流程测试
_ExchangeTest
extends
CheckTemplet
{
@Autowired
gawService
gawService
;
@Autowired
tawService
tawService
;
@Autowired
MobileService
mobileService
;
@Autowired
Authorization
authorization
;
private
DuibaLog
logger
=
DuibaLog
.
getLogger
();
int
uid
=
7028
;
@DataProvider
public
Object
[][]
providerMethod
(
Method
method
)
{
Object
[][]
result
=
null
;
if
(
method
.
getName
().
equals
(
"日期兑换限制测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
1
,
"194137"
,
"32555"
,
"65"
,
"兑吧卡密日期兑换限制未开始"
},
//case1
new
Object
[]{
2
,
"194138"
,
"32556"
,
"66"
,
"兑吧卡密日期兑换限制进行中"
},
//case2
new
Object
[]{
3
,
"194139"
,
"32557"
,
"67"
,
"兑吧卡密日期兑换限制已结束"
},
//case3
};
}
return
result
;
}
@Test
(
description
=
"兑吧卡密每人限购每日"
)
public
void
每人限购每日限制测试
()
throws
Exception
{
String
appItemId
=
"193955"
;
String
itemId
=
"32533"
;
String
skuId
=
"61"
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
String
message
=
""
;
try
{
//第一次兑换
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
status
.
equals
(
"processing"
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
i
--;
}
logger
.
info
(
"订单状态status:"
+
status
);
Assert
.
assertEquals
(
status
,
"success"
,
"校验轮询结果status失败"
);
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"今日已达兑换上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已达兑换上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验卡密每人限购每日限制成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"
+
itemId
+
"'"
);
}
}
@Test
(
description
=
"兑吧卡密每人限购永久"
)
public
void
每人限购永久限制测试
()
throws
Exception
{
String
appItemId
=
"194134"
;
String
itemId
=
"32552"
;
String
skuId
=
"62"
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
String
message
=
""
;
try
{
//第一次兑换
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
status
.
equals
(
"processing"
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
i
--;
}
Assert
.
assertEquals
(
status
,
"success"
,
"校验轮询结果status失败"
);
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已达兑换次数上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验卡密每人限购永久限制成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"
+
itemId
+
"'"
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '"
+
itemId
+
"'"
);
}
}
@Test
(
description
=
"兑吧卡密每人限购批次"
)
public
void
每人限购批次限制测试
()
throws
Exception
{
String
appItemId
=
"194135"
;
String
itemId
=
"32553"
;
String
skuId
=
"63"
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
String
message
=
""
;
try
{
//第一次兑换
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
status
.
equals
(
"processing"
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
i
--;
}
Assert
.
assertEquals
(
status
,
"success"
,
"校验轮询结果status失败"
);
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
//按钮文案不变
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验卡密每人限购批次限制成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"
+
itemId
+
"'"
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '"
+
itemId
+
"'"
);
}
}
@Test
(
description
=
"兑吧卡密每日限量"
)
public
void
每日限量测试
()
throws
Exception
{
String
appItemId
=
"194136"
;
String
itemId
=
"32554"
;
String
skuId
=
"64"
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
String
message
=
""
;
try
{
//第一次兑换
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
status
.
equals
(
"processing"
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
i
--;
}
Assert
.
assertEquals
(
status
,
"success"
,
"校验轮询结果status失败"
);
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"商品售罄"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"每日限量已兑完"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验卡密每日限量成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
jdbc
.
update
(
"DELETE FROM goods.tb_everyday_limit WHERE item_id = '"
+
itemId
+
"'"
);
}
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param itemId 商品id
* @param skuId skuId
* @param caseName 用例名称打印
* @throws Exception
*/
@Test
(
dataProvider
=
"providerMethod"
)
public
void
日期兑换限制测试
(
int
caseNum
,
String
appItemId
,
String
itemId
,
String
skuId
,
String
caseName
)
throws
Exception
{
String
message
=
""
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
logger
.
info
(
caseName
);
//兑换
try
{
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
//获取按钮状态
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
switch
(
caseNum
){
case
1
:
Assert
.
assertTrue
(
message
.
contains
(
"限2021-06-13至2021-06-18日期内兑换"
),
"校验message失败"
);
Assert
.
assertEquals
(
exchangeText
,
"限2021-06-13至2021-06-18日期内兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验卡密日期兑换限制未开始成功"
);
break
;
case
2
:
Assert
.
assertTrue
(
message
.
contains
(
""
),
"校验message失败"
);
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验卡密日期兑换限制进行中成功"
);
break
;
case
3
:
Assert
.
assertTrue
(
message
.
contains
(
"限2019-03-25至2019-03-25日期内兑换"
),
"校验日期兑换限制失败"
);
Assert
.
assertEquals
(
exchangeText
,
"限2019-03-25至2019-03-25日期内兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验卡密日期兑换限制已结束成功"
);
break
;
}
}
@Test
(
description
=
"兑吧卡密会员等级限制"
)
public
void
会员等级测试
()
throws
Exception
{
String
appItemId
=
"194140"
;
String
itemId
=
"32558"
;
String
skuId
=
"68"
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
String
message
=
""
;
//会员等级无法兑换
try
{
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
//会员等级可兑换,vip=5
Response
response
=
gawService
.
couponExchange
(
authorization
.
generateSignAutoLogin
(
"vc2HvzM439YBQiB6LVy4uxC4uWm"
,
7001
),
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
Assert
.
assertTrue
(
message
.
contains
(
"未达到会员等级要求"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验兑换结果失败"
);
logger
.
info
(
"校验卡密会员等级成功"
);
}
@Test
(
description
=
"兑吧卡密可售库存不足"
)
public
void
可售库存不足测试
()
throws
Exception
{
String
appItemId
=
"194141"
;
String
itemId
=
"32559"
;
String
skuId
=
"69"
;
String
message
=
""
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
//无库存兑换
try
{
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"商品售罄"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验message失败"
);
logger
.
info
(
"校验兑吧卡密可售库存不足成功"
);
}
@Test
(
description
=
"兑吧卡密SKU库存不足"
)
public
void
SKU
库存不足测试
()
throws
Exception
{
String
appItemId
=
"194142"
;
String
itemId
=
"32560"
;
String
skuId
=
"70"
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
logger
.
info
(
"订单号:"
+
orderId
);
Map
<
String
,
Object
>
mapOrder
=
jdbc
.
findSimpleResult
(
"SELECT * FROM "
+
Database
.
orders_consumer
+
"."
+
Database
.
orders11
+
" WHERE id = "
+
orderId
);
String
flowWork
=
String
.
valueOf
(
mapOrder
.
get
(
"flowwork_stage"
));
String
status
=
String
.
valueOf
(
mapOrder
.
get
(
"status"
));
logger
.
info
(
"数据库订单节点:"
+
flowWork
);
int
i
=
10
;
while
(
i
>
0
&&
!
flowWork
.
equals
(
"Create-tofail"
))
{
Thread
.
sleep
(
1000
);
mapOrder
=
jdbc
.
findSimpleResult
(
"SELECT * FROM "
+
Database
.
orders_consumer
+
"."
+
Database
.
orders11
+
" WHERE id = "
+
orderId
);
flowWork
=
String
.
valueOf
(
mapOrder
.
get
(
"flowwork_stage"
));
logger
.
info
(
"数据库订单节点:"
+
flowWork
);
i
--;
}
Assert
.
assertEquals
(
status
,
"create"
,
"校验订单status失败"
);
Assert
.
assertEquals
(
flowWork
,
"Create-tofail"
,
"校验订单节点flowwork失败"
);
logger
.
info
(
"校验兑吧卡密SKU库存不足成功"
);
}
}
src/test/java/http/cases/ExchangeTest/兑吧新优惠券_兑换流程测试_ExchangeTest.java
0 → 100644
View file @
ecaac2d5
package
http
.
cases
.
ExchangeTest
;
import
base.DuibaBase
;
import
base.DuibaBases
;
import
http.service.Activity.ManagerService
;
import
http.service.Authorization
;
import
http.service.app.MobileService
;
import
http.service.app.gawService
;
import
http.service.app.tawService
;
import
http.service.hd.DeveloperAccountService
;
import
http.service.hd.DappConfigService
;
import
org.apache.logging.log4j.core.pattern.AbstractStyleNameConverter
;
import
org.testng.annotations.AfterClass
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.DataProvider
;
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
;
import
java.lang.reflect.Method
;
import
java.util.HashMap
;
import
java.util.Map
;
import
utils.RedisUtil
;
import
static
io
.
restassured
.
RestAssured
.
given
;
/**
* Created by lvwenyan on 2019/3/19.
*/
public
class
兑吧新优惠券
_
兑换流程测试
_ExchangeTest
extends
CheckTemplet
{
@Autowired
gawService
gawService
;
@Autowired
tawService
tawService
;
@Autowired
MobileService
mobileService
;
@Autowired
Authorization
authorization
;
private
DuibaLog
logger
=
DuibaLog
.
getLogger
();
int
uid
=
7022
;
@DataProvider
public
Object
[][]
providerMethod
(
Method
method
)
{
Object
[][]
result
=
null
;
if
(
method
.
getName
().
equals
(
"日期兑换限制测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
1
,
"193853"
,
"32516"
,
"50"
,
"兑吧新优惠券日期兑换限制未开始"
},
//case1
new
Object
[]{
2
,
"193854"
,
"32517"
,
"51"
,
"兑吧新优惠券日期兑换限制进行中"
},
//case2
new
Object
[]{
3
,
"193855"
,
"32518"
,
"52"
,
"兑吧新优惠券日期兑换限制已结束"
},
//case3
};
}
return
result
;
}
@Test
(
description
=
"兑吧新优惠券每人限购每日"
)
public
void
每人限购每日限制测试
()
throws
Exception
{
String
appItemId
=
"193842"
;
String
itemId
=
"32512"
;
String
skuId
=
"39"
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
String
message
=
""
;
try
{
//第一次兑换
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
status
.
equals
(
"processing"
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
i
--;
}
logger
.
info
(
"订单状态status:"
+
status
);
Assert
.
assertEquals
(
status
,
"success"
,
"校验轮询结果status失败"
);
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"今日已达兑换上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已达兑换上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验优惠券每人限购每日限制成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"
+
itemId
+
"'"
);
}
}
@Test
(
description
=
"兑吧新优惠券每人限购永久"
)
public
void
每人限购永久限制测试
()
throws
Exception
{
String
appItemId
=
"193846"
;
String
itemId
=
"32513"
;
String
skuId
=
"43"
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
String
message
=
""
;
try
{
//第一次兑换
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
status
.
equals
(
"processing"
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
i
--;
}
Assert
.
assertEquals
(
status
,
"success"
,
"校验轮询结果status失败"
);
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已达兑换次数上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验优惠券每人限购永久限制成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"
+
itemId
+
"'"
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '"
+
itemId
+
"'"
);
}
}
@Test
(
description
=
"兑吧新优惠券每人限购批次"
)
public
void
每人限购批次限制测试
()
throws
Exception
{
String
appItemId
=
"193849"
;
String
itemId
=
"32514"
;
String
skuId
=
"46"
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
String
message
=
""
;
try
{
//第一次兑换
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
status
.
equals
(
"processing"
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
i
--;
}
Assert
.
assertEquals
(
status
,
"success"
,
"校验轮询结果status失败"
);
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
//按钮文案不变
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验优惠券每人限购批次限制成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"
+
itemId
+
"'"
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '"
+
itemId
+
"'"
);
}
}
@Test
(
description
=
"兑吧新优惠券每日限量"
)
public
void
每日限量测试
()
throws
Exception
{
String
appItemId
=
"193852"
;
String
itemId
=
"32515"
;
String
skuId
=
"49"
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
String
message
=
""
;
try
{
//第一次兑换
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
status
.
equals
(
"processing"
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
i
--;
}
Assert
.
assertEquals
(
status
,
"success"
,
"校验轮询结果status失败"
);
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"商品售罄"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"每日限量已兑完"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验优惠券每日限量成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
jdbc
.
update
(
"DELETE FROM goods.tb_everyday_limit WHERE item_id = '"
+
itemId
+
"'"
);
}
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param itemId 商品id
* @param skuId skuId
* @param caseName 用例名称打印
* @throws Exception
*/
@Test
(
dataProvider
=
"providerMethod"
)
public
void
日期兑换限制测试
(
int
caseNum
,
String
appItemId
,
String
itemId
,
String
skuId
,
String
caseName
)
throws
Exception
{
String
message
=
""
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
logger
.
info
(
caseName
);
//兑换
try
{
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
//获取按钮状态
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
switch
(
caseNum
){
case
1
:
Assert
.
assertTrue
(
message
.
contains
(
"限2021-05-01至2021-05-06日期内兑换"
),
"校验message失败"
);
Assert
.
assertEquals
(
exchangeText
,
"限2021-05-01至2021-05-06日期内兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验优惠券日期兑换限制未开始成功"
);
break
;
case
2
:
Assert
.
assertTrue
(
message
.
contains
(
""
),
"校验message失败"
);
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验优惠券日期兑换限制进行中成功"
);
break
;
case
3
:
Assert
.
assertTrue
(
message
.
contains
(
"限2019-03-20至2019-03-20日期内兑换"
),
"校验日期兑换限制失败"
);
Assert
.
assertEquals
(
exchangeText
,
"限2019-03-20至2019-03-20日期内兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验优惠券日期兑换限制已结束成功"
);
break
;
}
}
@Test
(
description
=
"兑吧新优惠券会员等级限制"
)
public
void
会员等级测试
()
throws
Exception
{
String
appItemId
=
"193881"
;
String
itemId
=
"32522"
;
String
skuId
=
"53"
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
String
message
=
""
;
//会员等级无法兑换
try
{
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
//会员等级可兑换,vip=5
Response
response
=
gawService
.
couponExchange
(
authorization
.
generateSignAutoLogin
(
"vc2HvzM439YBQiB6LVy4uxC4uWm"
,
7001
),
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
Assert
.
assertTrue
(
message
.
contains
(
"未达到会员等级要求"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验兑换结果失败"
);
logger
.
info
(
"校验优惠券会员等级成功"
);
}
@Test
(
description
=
"兑吧新优惠券可售库存不足"
)
public
void
可售库存不足测试
()
throws
Exception
{
String
appItemId
=
"193933"
;
String
itemId
=
"32529"
;
String
skuId
=
"60"
;
String
message
=
""
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
//无库存兑换
try
{
Response
response
=
gawService
.
couponExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"商品售罄"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验message失败"
);
logger
.
info
(
"校验兑吧新优惠券可售库存不足成功"
);
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param itemId 商品id
* @param caseName 用例名称打印
* @throws Exception
*/
// @Test(dataProvider = "providerMethod")
// public void 优惠券马上使用按钮测试(int caseNum, String appItemId, String itemId, String caseName)throws Exception{
//
// logger.info(caseName);
//
// //优惠券兑换
// String orderId = this.优惠券兑换订单(appItemId,itemId,uid);
//
// //优惠券兑换结果页
// Response resultResponse = crecordService.recordDetail(orderId,uid);
// //resultResponse.prettyPrint();
// String btnText = MatcherString.getString(resultResponse.asString(),"\"btnText\":\"(.*?)\",",1);
// String actualPay = MatcherString.getString(resultResponse.asString(),"\"actualPay\":\"(.*?)\",",1);
// String androidDownload = MatcherString.getString(resultResponse.asString(),"\"androidDownload\":\"(.*?)\",",1);
// String androidDownloadUrl = MatcherString.getString(resultResponse.asString(),"\"androidDownloadUrl\":\"(.*?)\",",1);
//
//
// //优惠券兑换记录页
// Thread.sleep(3000);
// Response detailResponse = tawService.detailItems(orderId,uid);
// detailResponse.prettyPrint();
// String useButtonText = detailResponse.jsonPath().getString("data[0].useButtonText");
// String iosDownloadUrl = detailResponse.jsonPath().getString("data[0].iosDownloadUrl");
//
// switch (caseNum){
//
// case 1:
// Assert.assertEquals(btnText,"马上使用","校验结果页按钮文案失败");
// Assert.assertEquals(actualPay,"10积分","校验结果页积分文案失败");
// Assert.assertEquals(androidDownload,"https://m2.mobike.com/active/fission_packet_joint/index.html","校验结果页按钮链接失败");
//
// Assert.assertEquals(useButtonText,"去使用","校验兑换记录页按钮文案失败");
// Assert.assertEquals(iosDownloadUrl,"https://m2.mobike.com/active/fission_packet_joint/index.html","校验兑换记录页按钮跳转链接失败");
// logger.info("校验优惠券商家落地页下载链接页面成功");
// break;
// case 2:
// Assert.assertEquals(btnText,"马上领取","校验结果页按钮文案失败");
// Assert.assertEquals(actualPay,"20积分","校验结果页积分文案失败");
// Assert.assertEquals(androidDownload,"https://u.163.com/aoshzxiaoshouxiaoshou4","校验结果页按钮链接失败");
//
// Assert.assertEquals(useButtonText,"去使用","校验兑换记录页按钮文案失败");
// Assert.assertEquals(iosDownloadUrl,"https://u.163.com/aoshzxiaoshouxiaoshou4","校验兑换记录页按钮跳转链接失败");
// logger.info("校验优惠券兑换记录页下载链接页面成功");
// break;
// case 3:
// Assert.assertEquals(btnText,"马上下载","校验结果页按钮文案失败");
// Assert.assertEquals(actualPay,"30积分","校验结果页积分文案失败");
// Assert.assertEquals(androidDownloadUrl,"//activity.m.duibatest.com.cn/log/redirect?url=https%3A%2F%2Fm.wkzuche.com%2Fh5%2F%23%2Factivity%2Fshare%3Fchannel%3Ddb%402018&dpm=2239.25.1.0&dcm=101.29710.172294.0","校验结果页按钮链接失败");
//
// Assert.assertEquals(useButtonText,"去使用","校验兑换记录页按钮文案失败");
// Assert.assertEquals(iosDownloadUrl,"https://m.wkzuche.com/h5/#/activity/share?channel=db@2018","校验兑换记录页按钮跳转链接失败");
// logger.info("校验优惠券链接券页面成功");
// break;
// }
//
// }
}
src/test/java/http/cases/ExchangeTest/兑吧新实物_兑换流程测试_ExchangeTest.java
View file @
ecaac2d5
...
...
@@ -42,17 +42,30 @@ public class 兑吧新实物_兑换流程测试_ExchangeTest extends CheckTemple
@Autowired
Authorization
authorization
;
private
DuibaLog
logger
=
DuibaLog
.
getLogger
();
int
uid
=
6866
;
@DataProvider
public
Object
[][]
providerMethod
(
Method
method
)
{
Object
[][]
result
=
null
;
if
(
method
.
getName
().
equals
(
"日期兑换限制测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
1
,
"193805"
,
"32506"
,
"兑吧新实物日期兑换限制未开始"
},
//case1
new
Object
[]{
2
,
"193806"
,
"32507"
,
"兑吧新实物日期兑换限制进行中"
},
//case2
new
Object
[]{
3
,
"193807"
,
"32508"
,
"兑吧新实物日期兑换限制已结束"
},
//case3
};
}
return
result
;
}
@Test
(
description
=
"兑吧新实物每人限购每日限制"
)
@Test
(
description
=
"兑吧新实物每人限购每日"
)
public
void
每人限购每日限制测试
()
throws
Exception
{
String
appItemId
=
"192950"
;
String
itemId
=
"32439"
;
String
message
=
""
;
try
{
//第一次兑换
Response
response
=
gawService
.
objectExchange
(
uid
,
appItemId
,
itemId
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
...
...
@@ -60,7 +73,16 @@ public class 兑吧新实物_兑换流程测试_ExchangeTest extends CheckTemple
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
Assert
.
assertEquals
(
status
,
"wait_delivery"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
status
.
equals
(
"processing"
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
i
--;
}
Assert
.
assertEquals
(
status
,
"wait_delivery"
,
"校验轮询结果status失败"
);
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
...
...
@@ -81,7 +103,67 @@ public class 兑吧新实物_兑换流程测试_ExchangeTest extends CheckTemple
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已达兑换上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户每日限制消费成功"
);
logger
.
info
(
"校验实物每人限购每日限制成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"
+
itemId
+
"'"
);
}
}
@Test
(
description
=
"兑吧新实物每人限购永久"
)
public
void
每人限购永久限制测试
()
throws
Exception
{
String
appItemId
=
"193756"
;
String
itemId
=
"32500"
;
String
message
=
""
;
try
{
//第一次兑换
Response
response
=
gawService
.
objectExchange
(
uid
,
appItemId
,
itemId
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
status
.
equals
(
"processing"
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
i
--;
}
Assert
.
assertEquals
(
status
,
"wait_delivery"
,
"校验轮询结果status失败"
);
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
objectExchange
(
uid
,
appItemId
,
itemId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已达兑换次数上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物每人限购永久限制成功"
);
}
catch
(
Exception
e
){
...
...
@@ -89,6 +171,8 @@ public class 兑吧新实物_兑换流程测试_ExchangeTest extends CheckTemple
}
finally
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"
+
itemId
+
"'"
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '"
+
itemId
+
"'"
);
}
...
...
@@ -96,6 +180,274 @@ public class 兑吧新实物_兑换流程测试_ExchangeTest extends CheckTemple
}
@Test
(
description
=
"兑吧新实物每人限购周期"
)
public
void
每人限购周期限制测试
()
throws
Exception
{
String
appItemId
=
"193757"
;
String
itemId
=
"32501"
;
String
message
=
""
;
try
{
//第一次兑换
Response
response
=
gawService
.
objectExchange
(
uid
,
appItemId
,
itemId
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
status
.
equals
(
"processing"
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
i
--;
}
Assert
.
assertEquals
(
status
,
"wait_delivery"
,
"校验轮询结果status失败"
);
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
objectExchange
(
uid
,
appItemId
,
itemId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已达兑换次数上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物每人限购周期限制成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"
+
itemId
+
"'"
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '"
+
itemId
+
"'"
);
}
}
@Test
(
description
=
"兑吧新实物每日限量"
)
public
void
每日限量测试
()
throws
Exception
{
String
appItemId
=
"193801"
;
String
itemId
=
"32505"
;
String
message
=
""
;
try
{
//第一次兑换
Response
response
=
gawService
.
objectExchange
(
uid
,
appItemId
,
itemId
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
status
.
equals
(
"processing"
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
i
--;
}
Assert
.
assertEquals
(
status
,
"wait_delivery"
,
"校验轮询结果status失败"
);
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
objectExchange
(
uid
,
appItemId
,
itemId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"商品售罄"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"每日限量已兑完"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物每日限量成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
jdbc
.
update
(
"DELETE FROM goods.tb_everyday_limit WHERE item_id = '"
+
itemId
+
"'"
);
}
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param itemId 商品id
* @param caseName 用例名称打印
* @throws Exception
*/
@Test
(
dataProvider
=
"providerMethod"
)
public
void
日期兑换限制测试
(
int
caseNum
,
String
appItemId
,
String
itemId
,
String
caseName
)
throws
Exception
{
String
message
=
""
;
logger
.
info
(
caseName
);
//兑换
try
{
Response
response
=
gawService
.
objectExchange
(
uid
,
appItemId
,
itemId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
//获取按钮状态
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
itemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
switch
(
caseNum
){
case
1
:
Assert
.
assertTrue
(
message
.
contains
(
"限2021-04-01至2021-04-08日期内兑换"
),
"校验message失败"
);
Assert
.
assertEquals
(
exchangeText
,
"限2021-04-01至2021-04-08日期内兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制未开始成功"
);
break
;
case
2
:
Assert
.
assertTrue
(
message
.
contains
(
""
),
"校验message失败"
);
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制进行中成功"
);
break
;
case
3
:
Assert
.
assertTrue
(
message
.
contains
(
"限2019-03-20至2019-03-20日期内兑换"
),
"校验日期兑换限制失败"
);
Assert
.
assertEquals
(
exchangeText
,
"限2019-03-20至2019-03-20日期内兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制已结束成功"
);
break
;
}
}
@Test
(
description
=
"兑吧新实物会员等级限制"
)
public
void
会员等级测试
()
throws
Exception
{
String
appItemId
=
"193808"
;
String
itemId
=
"32509"
;
String
message
=
""
;
//会员等级无法兑换
try
{
Response
response
=
gawService
.
objectExchange
(
uid
,
appItemId
,
itemId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
//会员等级可兑换,vip=5
Response
response
=
gawService
.
objectExchange
(
authorization
.
generateSignAutoLogin
(
"vc2HvzM439YBQiB6LVy4uxC4uWm"
,
7001
),
appItemId
,
itemId
,
"16"
);
response
.
prettyPrint
();
Assert
.
assertTrue
(
message
.
contains
(
"未达到会员等级要求"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验兑换结果失败"
);
logger
.
info
(
"校验实物会员等级成功"
);
}
@Test
(
description
=
"兑吧新实物可售库存不足"
)
public
void
可售库存不足测试
()
throws
Exception
{
String
appItemId
=
"193840"
;
String
itemId
=
"32511"
;
String
skuId
=
"37"
;
String
message
=
""
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
//无库存兑换
try
{
Response
response
=
gawService
.
objectExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"商品售罄"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验message失败"
);
logger
.
info
(
"校验兑吧新实物可售库存不足成功"
);
}
@Test
(
description
=
"兑吧新实物SKU库存不足"
)
public
void
SKU
库存不足测试
()
throws
Exception
{
String
appItemId
=
"193839"
;
String
itemId
=
"32510"
;
String
skuId
=
"34"
;
Map
cookies
=
authorization
.
dafuwengLogin
(
uid
);
Response
response
=
gawService
.
objectExchange
(
cookies
,
appItemId
,
itemId
,
skuId
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
logger
.
info
(
"订单号:"
+
orderId
);
Map
<
String
,
Object
>
mapOrder
=
jdbc
.
findSimpleResult
(
"SELECT * FROM "
+
Database
.
orders_consumer
+
"."
+
Database
.
orders10
+
" WHERE id = "
+
orderId
);
String
flowWork
=
String
.
valueOf
(
mapOrder
.
get
(
"flowwork_stage"
));
String
status
=
String
.
valueOf
(
mapOrder
.
get
(
"status"
));
logger
.
info
(
"数据库订单节点:"
+
flowWork
);
int
i
=
10
;
while
(
i
>
0
&&
!
flowWork
.
equals
(
"Create-tofail"
))
{
Thread
.
sleep
(
1000
);
mapOrder
=
jdbc
.
findSimpleResult
(
"SELECT * FROM "
+
Database
.
orders_consumer
+
"."
+
Database
.
orders10
+
" WHERE id = "
+
orderId
);
flowWork
=
String
.
valueOf
(
mapOrder
.
get
(
"flowwork_stage"
));
logger
.
info
(
"数据库订单节点:"
+
flowWork
);
i
--;
}
Assert
.
assertEquals
(
status
,
"create"
,
"校验订单status失败"
);
Assert
.
assertEquals
(
flowWork
,
"Create-tofail"
,
"校验订单节点flowwork失败"
);
logger
.
info
(
"校验兑吧新实物SKU库存不足成功"
);
}
...
...
src/test/java/http/cases/ExchangeTest/兑吧老优惠券_兑换流程测试_ExchangeTest.java
View file @
ecaac2d5
...
...
@@ -696,59 +696,6 @@ public class 兑吧老优惠券_兑换流程测试_ExchangeTest extends CheckTem
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param token token
* @param caseName 用例名称打印
* @throws Exception
*/
//@Test(dataProvider = "providerMethod")
public
void
自有优惠券会员等级测试
(
int
caseNum
,
String
appItemId
,
String
token
,
String
caseName
)
throws
Exception
{
logger
.
info
(
caseName
);
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"appItemId"
,
appItemId
);
map
.
put
(
"token"
,
token
);
//会员等级不符,详情页按钮“如何获得兑换资格”
Response
detailResponse
=
mobileService
.
appItemDetail
(
appItemId
,
uid
);
detailResponse
.
prettyPrint
();
//会员等级不符,兑换
Response
failResponse
=
given
().
contentType
(
"application/x-www-form-urlencoded;charset=UTF-8"
).
cookies
(
authorization
.
dafuwengLogin
(
uid
)).
params
(
map
).
post
(
url
+
"/couponExchange/exchange"
);
failResponse
.
prettyPrint
();
//会员等级符合条件,兑换,vip=5
Response
response
=
couponExchangeService
.
couponExchange
(
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
3402
),
appItemId
,
""
);
response
.
prettyPrint
();
switch
(
caseNum
){
case
1
:
Assert
.
assertEquals
(
detailResponse
.
asString
().
contains
(
"如何获得兑换资格"
),
true
);
Assert
.
assertEquals
(
failResponse
.
jsonPath
().
getString
(
"success"
),
"false"
,
"校验兑换结果失败"
);
Assert
.
assertEquals
(
failResponse
.
jsonPath
().
getString
(
"message"
),
"会员等级不符,请挑选其他吧(15)"
,
"校验兑换结果消息失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验兑换结果失败"
);
logger
.
info
(
"校验优惠券会员等级范围成功"
);
break
;
case
2
:
Assert
.
assertEquals
(
detailResponse
.
asString
().
contains
(
"如何获得兑换资格"
),
true
);
Assert
.
assertEquals
(
failResponse
.
jsonPath
().
getString
(
"success"
),
"false"
,
"校验兑换结果失败"
);
Assert
.
assertEquals
(
failResponse
.
jsonPath
().
getString
(
"message"
),
"会员等级不符,请挑选其他吧(15)"
,
"校验兑换结果消息失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验兑换结果失败"
);
logger
.
info
(
"校验优惠券会员特定等级成功"
);
break
;
}
}
@Test
(
description
=
"兑吧优惠券会员等级测试"
)
public
void
会员等级测试
()
throws
Exception
{
...
...
src/test/java/http/cases/ExchangeTest/多档位话费_兑换流程测试_ExchangeTest.java
View file @
ecaac2d5
...
...
@@ -146,7 +146,7 @@ public class 多档位话费_兑换流程测试_ExchangeTest extends CheckTemple
message
=
e
.
toString
();
}
logger
.
info
(
message
);
logger
.
info
(
"message: "
+
message
);
//获取按钮状态
Response
detailResponse
=
mobileService
.
detail
(
authorization
.
dafuwengLogin
(
uid
),
"1"
);
...
...
src/test/java/http/cases/ExchangeTest/自有_商品兑换限制/自有新优惠券_兑换限制测试.java
0 → 100644
View file @
ecaac2d5
package
http
.
cases
.
ExchangeTest
.
自有
_
商品兑换限制
;
import
http.cases.ExchangeTest.CheckTemplet
;
import
http.service.Activity.ManagerService
;
import
http.service.Authorization
;
import
http.service.app.*
;
import
http.service.hd.DappConfigService
;
import
http.service.hd.DeveloperAccountService
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.DataProvider
;
import
org.testng.annotations.Test
;
import
utils.MatcherString
;
import
java.lang.reflect.Method
;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* Created by mabo on 2019/3/25
*/
public
class
自有新优惠券
_
兑换限制测试
extends
CheckTemplet
{
@Autowired
http
.
service
.
app
.
gawService
gawService
;
@Autowired
http
.
service
.
app
.
tawService
tawService
;
@Autowired
MobileService
mobileService
;
@Autowired
Authorization
authorization
;
private
int
uid
=
7003
;
private
String
consumerId
=
"100144145"
;
private
String
url
=
"http://activity.m.duibatest.com.cn"
;
@BeforeMethod
public
void
beforeMethod
()
{
try
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record where consumer_id = ?"
,
consumerId
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only where consumer_id = ?"
,
consumerId
);
jdbc
.
update
(
"DELETE FROM goods.tb_everyday_limit where app_item_id=193845"
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@DataProvider
public
Object
[][]
providerMethod
(
Method
method
)
{
Object
[][]
result
=
null
;
if
(
method
.
getName
().
equals
(
"日期兑换限制测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
1
,
"194281"
,
78
,
"实物日期兑换限制未开始测试"
},
//case1
new
Object
[]{
2
,
"194282"
,
79
,
"实物日期兑换限制进行中测试"
},
//case2
new
Object
[]{
3
,
"194283"
,
80
,
"实物日期兑换限制已结束"
},
//case3
};
}
if
(
method
.
getName
().
equals
(
"库存不足测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
"193847"
,
"实物库存不足测试"
},
//case1
};
}
return
result
;
}
@Test
public
void
用户每日限制消费测试
()
throws
Exception
{
String
appItemId
=
"193841"
;
try
{
//第一次兑换
Response
response
=
gawService
.
couponExchange
(
uid
,
appItemId
,
38
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
couponExchange
(
uid
,
appItemId
,
38
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"今日已达兑换上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已达兑换上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户每日限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
}
}
@Test
public
void
用户永久限制消费测试
()
throws
Exception
{
String
appItemId
=
"193843"
;
try
{
//第一次兑换
Response
response
=
gawService
.
couponExchange
(
uid
,
appItemId
,
40
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
couponExchange
(
uid
,
appItemId
,
40
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已达兑换次数上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户永久限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '"+itemId+"'");
}
}
@Test
public
void
每日兑换上限测试
()
throws
Exception
{
String
appItemId
=
"193845"
;
try
{
//第一次兑换
Response
response
=
gawService
.
couponExchange
(
uid
,
appItemId
,
42
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
couponExchange
(
uid
,
appItemId
,
42
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"商品售罄"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"每日限量已兑完"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物每日兑换上限成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
//清掉每日兑换限制数据
// jdbc.update("DELETE FROM goods.tb_everyday_limit WHERE item_id = '"+itemId+"'");
}
}
/**
* @param appItemId 商品入库Id
* @param caseName 用例名称打印
* @throws Exception
*/
@Test
(
dataProvider
=
"providerMethod"
)
public
void
库存不足测试
(
String
appItemId
,
String
caseName
)
throws
Exception
{
logger
.
info
(
caseName
);
String
message
=
null
;
try
{
//兑换
Response
response
=
gawService
.
couponExchange
(
uid
,
appItemId
,
44
);
}
catch
(
Exception
e
){
message
=
e
.
getMessage
();
logger
.
info
(
"message:"
+
message
);
}
//获取按钮状态
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"兑换按钮:"
+
exchangeText
);
Assert
.
assertTrue
(
message
.
contains
(
"商品售罄"
),
"校验message失败"
);
Assert
.
assertEquals
(
exchangeText
,
"商品售罄"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物库存成功"
);
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param caseName 用例名称打印
* @throws Exception
*/
@Test
(
dataProvider
=
"providerMethod"
)
public
void
日期兑换限制测试
(
int
caseNum
,
String
appItemId
,
int
skuId
,
String
caseName
)
throws
Exception
{
logger
.
info
(
caseName
);
String
message
=
null
;
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"appItemId"
,
appItemId
);
Response
response
=
null
;
//兑换
try
{
response
=
gawService
.
couponExchange
(
uid
,
appItemId
,
skuId
);
}
catch
(
Exception
e
){
message
=
e
.
getMessage
();
logger
.
info
(
"message:"
+
message
);
}
//获取按钮状态
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
switch
(
caseNum
){
case
1
:
// Assert.assertEquals(response.jsonPath().getString("message"),"请在限定时间内兑换哦(13)","校验日期兑换限制失败");
Assert
.
assertTrue
(
message
.
contains
(
"限2028-04-30至2029-04-17日期内兑换"
),
"校验日期兑换限制失败"
);
Assert
.
assertEquals
(
exchangeText
,
"限2028-04-30至2029-04-17日期内兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制未开始成功"
);
break
;
case
2
:
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验日期兑换限制失败"
);
// Assert.assertTrue(message.contains("success"),"校验日期兑换限制失败");
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制进行中成功"
);
break
;
case
3
:
// Assert.assertEquals(response.jsonPath().getString("message"),"已结束","校验日期兑换限制失败");
Assert
.
assertTrue
(
message
.
contains
(
"限2019-03-27至2019-03-27日期内兑换"
),
"校验日期兑换限制失败"
);
Assert
.
assertEquals
(
exchangeText
,
"限2019-03-27至2019-03-27日期内兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制已结束成功"
);
break
;
}
}
@Test
public
void
会员等级测试
()
throws
Exception
{
String
appItemId
=
"193848"
;
String
message
=
""
;
//会员等级无法兑换
try
{
Response
response
=
gawService
.
couponExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
45
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
//会员等级可兑换,vip=5
Response
response
=
gawService
.
couponExchange
(
authorization
.
generateSignAutoLogin
(
"3tzVcss7SnAvA5ppT1m1rMPhaBcD"
,
7083
,
1
),
appItemId
,
45
);
response
.
prettyPrint
();
Assert
.
assertTrue
(
message
.
contains
(
"未达到会员等级要求"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验兑换结果失败"
);
logger
.
info
(
"校验实物会员等级成功"
);
}
@Test
public
void
用户周期限制消费测试
()
throws
Exception
{
String
appItemId
=
"193844"
;
try
{
//第一次兑换
Response
response
=
gawService
.
couponExchange
(
uid
,
appItemId
,
41
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
mobileService
.
orderStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
couponExchange
(
uid
,
appItemId
,
41
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已达兑换次数上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户周期限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
}
}
}
src/test/java/http/cases/ExchangeTest/自有_商品兑换限制/自有新卡密_兑换限制测试.java
0 → 100644
View file @
ecaac2d5
package
http
.
cases
.
ExchangeTest
.
自有
_
商品兑换限制
;
import
http.cases.ExchangeTest.CheckTemplet
;
import
http.service.Authorization
;
import
http.service.app.MobileService
;
import
io.restassured.RestAssured
;
import
io.restassured.response.Response
;
import
org.apache.http.client.params.ClientPNames
;
import
org.apache.http.params.CoreConnectionPNames
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.DataProvider
;
import
org.testng.annotations.Test
;
import
utils.MatcherString
;
import
java.lang.reflect.Method
;
import
java.sql.SQLException
;
import
static
io
.
restassured
.
RestAssured
.
config
;
import
static
io
.
restassured
.
RestAssured
.
given
;
import
static
io
.
restassured
.
config
.
HttpClientConfig
.
httpClientConfig
;
import
static
io
.
restassured
.
config
.
RestAssuredConfig
.
newConfig
;
/**
* Created by mabo on 2019/3/26
*/
public
class
自有新卡密
_
兑换限制测试
extends
CheckTemplet
{
@Autowired
http
.
service
.
app
.
gawService
gawService
;
@Autowired
http
.
service
.
app
.
tawService
tawService
;
@Autowired
MobileService
mobileService
;
@Autowired
Authorization
authorization
;
private
int
uid
=
7004
;
private
String
consumerId
=
"100144146"
;
private
String
url
=
"http://activity.m.duibatest.com.cn"
;
@BeforeMethod
public
void
beforeMethod
()
{
try
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record where consumer_id = ?"
,
consumerId
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only where consumer_id = ?"
,
consumerId
);
jdbc
.
update
(
"DELETE FROM goods.tb_everyday_limit where app_item_id=193845"
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
// @Test
// public void test(){
//
// Response response = given().get("http://localhost:1112/sql/test");
// response.prettyPrint();
// }
@DataProvider
public
Object
[][]
providerMethod
(
Method
method
)
{
Object
[][]
result
=
null
;
if
(
method
.
getName
().
equals
(
"日期兑换限制测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
1
,
"193827"
,
"实物日期兑换限制未开始测试"
},
//case1
new
Object
[]{
2
,
"193828"
,
"实物日期兑换限制进行中测试"
},
//case2
new
Object
[]{
3
,
"193829"
,
"实物日期兑换限制已结束"
},
//case3
};
}
if
(
method
.
getName
().
equals
(
"库存不足测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
"193847"
,
"实物库存不足测试"
},
//case1
};
}
return
result
;
}
@Test
public
void
用户每日限制消费测试
()
throws
Exception
{
String
appItemId
=
"193850"
;
int
skuId
=
47
;
try
{
//第一次兑换
Response
response
=
gawService
.
couponExchange
(
uid
,
appItemId
,
47
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
couponExchange
(
uid
,
appItemId
,
47
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"今日已达兑换上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已达兑换上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户每日限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
}
}
// @Test
// public void 用户永久限制消费测试() throws Exception {
//
// String appItemId = "193843";
//
// try{
//
// //第一次兑换
// Response response = gawService.couponExchange(uid, appItemId,40);
// String orderId = response.jsonPath().getString("data.orderId");
// //获取兑换结果
// response = tawService.orderStatus(orderId,uid);
// response.prettyPrint();
// String message = response.jsonPath().getString("message");
// int i = 10;
// //异步接口,直到兑换成功
// while (i > 0 && "兑换正在处理中...".equals(message)) {
// Thread.sleep(1000);
// response = tawService.orderStatus(orderId,uid);
// response.prettyPrint();
// message = response.jsonPath().getString("message");
// i--;
// }
//
// Response detailResponse = mobileService.appItemDetail(authorization.dafuwengLogin(uid),appItemId);
// detailResponse.prettyPrint();
// String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
// logger.info("商品兑换按钮:" + exchangeText);
//
// //第二次兑换
// Thread.sleep(3000);
// try{
// response = gawService.couponExchange(uid, appItemId,40);
// response.prettyPrint();
//
// }catch (Exception e){
// message = e.toString();
// }
// logger.info(message);
//
// Assert.assertTrue(message.contains("已达兑换次数上限"),"校验message失败");
// Assert.assertTrue(message.contains("\"success\":false"),"校验success失败");
//
// Assert.assertEquals(exchangeText,"已达兑换次数上限","校验兑换按钮失败");
// logger.info("校验实物用户永久限制消费成功");
//
// }catch (Exception e){
//
// throw new Exception("异常信息打印:" + e);
//
// }finally {
//// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
//// jdbc.update("DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '"+itemId+"'");
//
//
//
// }
//
//
// }
//
// @Test
// public void 每日兑换上限测试() throws Exception {
//
// String appItemId = "193845";
// try{
//
// //第一次兑换
// Response response = gawService.couponExchange(uid, appItemId,42);
// String orderId = response.jsonPath().getString("data.orderId");
// //获取兑换结果
// response = tawService.orderStatus(orderId,uid);
// response.prettyPrint();
// String message = response.jsonPath().getString("message");
// int i = 10;
// //异步接口,直到兑换成功
// while (i > 0 && "兑换正在处理中...".equals(message)) {
// Thread.sleep(1000);
// response = mobileService.orderStatusQuery(uid,orderId);
// response.prettyPrint();
// message = response.jsonPath().getString("message");
// i--;
// }
//
// Response detailResponse = mobileService.appItemDetail(authorization.dafuwengLogin(uid),appItemId);
// detailResponse.prettyPrint();
// String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
// logger.info("商品兑换按钮:" + exchangeText);
//
// //第二次兑换
// Thread.sleep(3000);
// try{
// response = gawService.couponExchange(uid, appItemId,42);
// response.prettyPrint();
//
// }catch (Exception e){
// message = e.toString();
// }
// logger.info(message);
//
// Assert.assertTrue(message.contains("商品售罄"),"校验message失败");
// Assert.assertTrue(message.contains("\"success\":false"),"校验success失败");
//
// Assert.assertEquals(exchangeText,"每日限量已兑完","校验兑换按钮失败");
// logger.info("校验实物每日兑换上限成功");
//
// }catch (Exception e){
//
// throw new Exception("异常信息打印:" + e);
//
// }finally {
// //清掉每日兑换限制数据
//// jdbc.update("DELETE FROM goods.tb_everyday_limit WHERE item_id = '"+itemId+"'");
//
// }
//
//
// }
//
// /**
// * @param appItemId 商品入库Id
// * @param caseName 用例名称打印
// * @throws Exception
// */
// @Test(dataProvider = "providerMethod")
// public void 库存不足测试(String appItemId, String caseName) throws Exception{
//
//
// logger.info(caseName);
//
// String message=null;
// try{
// //兑换
// Response response = gawService.couponExchange(uid, appItemId,44);
//
// }catch (Exception e){
// message = e.getMessage();
// logger.info("message:"+message);
//
// }
//
//
//
// //获取按钮状态
// Response detailResponse = mobileService.appItemDetail(authorization.dafuwengLogin(uid),appItemId);
// String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
// logger.info("兑换按钮:" + exchangeText);
//
//
// Assert.assertTrue(message.contains("商品售罄"),"校验message失败");
// Assert.assertEquals(exchangeText,"商品售罄","校验马上兑换按钮状态失败");
// logger.info("校验实物库存成功");
//
// }
//
//// /**
//// * @param caseNum 用例编号
//// * @param appItemId 商品入库Id
//// * @param caseName 用例名称打印
//// * @throws Exception
//// */
//// @Test(dataProvider = "providerMethod")
//// public void 日期兑换限制测试(int caseNum, String appItemId, String caseName) throws Exception{
////
//// logger.info(caseName);
//// String message = null;
////
//// Map<String,String> map = new HashMap<>();
//// map.put("appItemId",appItemId);
//// Response response =null;
////
//// //兑换
//// try{
//// response = couponExchangeService.couponExchange(authorization.dafuwengLogin(uid), appItemId, null);
////
//// }catch (Exception e){
//// message = e.getMessage();
//// logger.info("message:"+message);
////
//// }
////
//// //获取按钮状态
//// Response detailResponse = mobileService.appItemDetail(authorization.dafuwengLogin(uid),appItemId);
//// String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
//// logger.info("商品兑换按钮:" + exchangeText);
////
//// switch (caseNum){
////
//// case 1:
////// Assert.assertEquals(response.jsonPath().getString("message"),"请在限定时间内兑换哦(13)","校验日期兑换限制失败");
//// Assert.assertTrue(message.contains("请在限定时间内兑换哦(13)"),"校验日期兑换限制失败");
//// Assert.assertEquals(exchangeText,"即将开始","校验马上兑换按钮状态失败");
//// logger.info("校验实物日期兑换限制未开始成功");
//// break;
////
//// case 2:
//// Assert.assertEquals(response.jsonPath().getString("success"),"true","校验日期兑换限制失败");
////// Assert.assertTrue(message.contains("success"),"校验日期兑换限制失败");
//// Assert.assertEquals(exchangeText,"马上兑换","校验马上兑换按钮状态失败");
//// logger.info("校验实物日期兑换限制进行中成功");
//// break;
////
//// case 3:
////// Assert.assertEquals(response.jsonPath().getString("message"),"已结束","校验日期兑换限制失败");
//// Assert.assertTrue(message.contains("已结束"),"校验日期兑换限制失败");
//// Assert.assertEquals(exchangeText,"已结束","校验马上兑换按钮状态失败");
//// logger.info("校验实物日期兑换限制已结束成功");
//// break;
////
//// }
////
////
//// }
//
// @Test
// public void 会员等级测试()throws Exception{
//
// String appItemId = "193821";
// String message = "";
//
// //会员等级无法兑换
// try{
// Response response = gawService.couponExchange(authorization.dafuwengLogin(uid), appItemId,44);
// response.prettyPrint();
//
// }catch (Exception e){
// message = e.toString();
// }
// logger.info(message);
//
// //会员等级可兑换,vip=5
// Response response = gawService.couponExchange(authorization.generateSignAutoLogin("2wGQc3MZaQsqYFWcX4gguya5PnnS",3402,1),appItemId,44);
// response.prettyPrint();
//
// Assert.assertTrue(message.contains("会员等级不符,请挑选其他吧(15)"),"校验message失败");
// Assert.assertTrue(message.contains("\"success\":false"),"校验success失败");
// Assert.assertEquals(response.jsonPath().getString("success"),"true","校验兑换结果失败");
// logger.info("校验实物会员等级成功");
//
// }
//
// @Test
// public void 用户周期限制消费测试() throws Exception {
//
// String appItemId = "193844";
// try{
//
// //第一次兑换
// Response response = gawService.couponExchange(uid, appItemId,41);
// response.prettyPrint();
// String orderId = response.jsonPath().getString("data.orderId");
// //获取兑换结果
// response = mobileService.orderStatusQuery(uid,orderId);
// response.prettyPrint();
// String message = response.jsonPath().getString("message");
// int i = 10;
// //异步接口,直到兑换成功
// while (i > 0 && "兑换正在处理中...".equals(message)) {
// Thread.sleep(1000);
// response = mobileService.orderStatusQuery(uid,orderId);
// response.prettyPrint();
// message = response.jsonPath().getString("message");
// i--;
// }
//
// Response detailResponse = mobileService.appItemDetail(authorization.dafuwengLogin(uid),appItemId);
// detailResponse.prettyPrint();
// String exchangeText = MatcherString.getString(detailResponse.asString(), "\"exchangeText\":\"(.*?)\",", 1);
// logger.info("商品兑换按钮:" + exchangeText);
//
// //第二次兑换
// Thread.sleep(3000);
// try{
// response = gawService.couponExchange(uid, appItemId,41);
// response.prettyPrint();
//
// }catch (Exception e){
// message = e.toString();
// }
// logger.info(message);
//
// Assert.assertTrue(message.contains("已达兑换次数上限"),"校验message失败");
// Assert.assertTrue(message.contains("\"success\":false"),"校验success失败");
//
// Assert.assertEquals(exchangeText,"已达兑换次数上限","校验兑换按钮失败");
// logger.info("校验实物用户周期限制消费成功");
//
// }catch (Exception e){
//
// throw new Exception("异常信息打印:" + e);
//
// }finally {
//// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
//
// }
//
//
// }
}
src/test/java/http/cases/ExchangeTest/自有_商品兑换限制/自有新虚拟商品_充值_兑换限制.java
0 → 100644
View file @
ecaac2d5
package
http
.
cases
.
ExchangeTest
.
自有
_
商品兑换限制
;
import
http.cases.ExchangeTest.CheckTemplet
;
import
http.service.Authorization
;
import
http.service.app.MobileService
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.DataProvider
;
import
org.testng.annotations.Test
;
import
utils.MatcherString
;
import
java.lang.reflect.Method
;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* Created by mabo on 2019/3/26
*/
public
class
自有新虚拟商品
_
充值
_
兑换限制
extends
CheckTemplet
{
@Autowired
http
.
service
.
app
.
gawService
gawService
;
@Autowired
http
.
service
.
app
.
tawService
tawService
;
@Autowired
MobileService
mobileService
;
@Autowired
Authorization
authorization
;
private
int
uid
=
7005
;
private
String
consumerId
=
"100144147"
;
private
String
url
=
"http://activity.m.duibatest.com.cn"
;
private
Map
cookie
=
null
;
@BeforeMethod
public
void
beforeMethod
()
{
try
{
cookie
=
authorization
.
dafuwengLogin
(
uid
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record where consumer_id = ?"
,
consumerId
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only where consumer_id = ?"
,
consumerId
);
jdbc
.
update
(
"DELETE FROM goods.tb_everyday_limit where app_item_id=193883"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
@DataProvider
public
Object
[][]
providerMethod
(
Method
method
)
{
Object
[][]
result
=
null
;
if
(
method
.
getName
().
equals
(
"日期兑换限制测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
1
,
"194257"
,
75
,
"实物日期兑换限制未开始测试"
},
//case1
new
Object
[]{
2
,
"194258"
,
76
,
"实物日期兑换限制进行中测试"
},
//case2
new
Object
[]{
3
,
"194259"
,
77
,
"实物日期兑换限制已结束"
},
//case3
};
}
if
(
method
.
getName
().
equals
(
"库存不足测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
"193885"
,
"实物库存不足测试"
},
//case1
};
}
return
result
;
}
@Test
public
void
用户每日限制消费测试
()
throws
Exception
{
String
appItemId
=
"193851"
;
try
{
//第一次兑换
Response
response
=
gawService
.
virtualExchange
(
cookie
,
appItemId
,
48
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
virtualExchange
(
cookie
,
appItemId
,
48
);;
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"今日已达兑换上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已达兑换上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户每日限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
}
}
@Test
public
void
用户永久限制消费测试
()
throws
Exception
{
String
appItemId
=
"193882"
;
try
{
//第一次兑换
Response
response
=
gawService
.
virtualExchange
(
cookie
,
appItemId
,
54
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
virtualExchange
(
cookie
,
appItemId
,
54
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已达兑换次数上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户永久限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '"+itemId+"'");
}
}
@Test
public
void
每日兑换上限测试
()
throws
Exception
{
String
appItemId
=
"193883"
;
try
{
//第一次兑换
Response
response
=
gawService
.
virtualExchange
(
cookie
,
appItemId
,
55
);
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
virtualExchange
(
cookie
,
appItemId
,
55
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"商品售罄"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"每日限量已兑完"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物每日兑换上限成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
//清掉每日兑换限制数据
// jdbc.update("DELETE FROM goods.tb_everyday_limit WHERE item_id = '"+itemId+"'");
}
}
/**
* @param appItemId 商品入库Id
* @param caseName 用例名称打印
* @throws Exception
*/
@Test
(
dataProvider
=
"providerMethod"
)
public
void
库存不足测试
(
String
appItemId
,
String
caseName
)
throws
Exception
{
logger
.
info
(
caseName
);
String
message
=
null
;
try
{
//兑换
Response
response
=
gawService
.
virtualExchange
(
cookie
,
appItemId
,
57
);
}
catch
(
Exception
e
){
message
=
e
.
getMessage
();
logger
.
info
(
"message:"
+
message
);
}
//获取按钮状态
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"兑换按钮:"
+
exchangeText
);
Assert
.
assertTrue
(
message
.
contains
(
"商品售罄"
),
"校验message失败"
);
Assert
.
assertEquals
(
exchangeText
,
"商品售罄"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物库存成功"
);
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param caseName 用例名称打印
* @throws Exception
*/
@Test
(
dataProvider
=
"providerMethod"
)
public
void
日期兑换限制测试
(
int
caseNum
,
String
appItemId
,
int
skuId
,
String
caseName
)
throws
Exception
{
logger
.
info
(
caseName
);
String
message
=
null
;
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"appItemId"
,
appItemId
);
Response
response
=
null
;
//兑换
try
{
response
=
gawService
.
virtualExchange
(
cookie
,
appItemId
,
skuId
);
}
catch
(
Exception
e
){
message
=
e
.
getMessage
();
logger
.
info
(
"message:"
+
message
);
}
//获取按钮状态
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
switch
(
caseNum
){
case
1
:
// Assert.assertEquals(response.jsonPath().getString("message"),"请在限定时间内兑换哦(13)","校验日期兑换限制失败");
Assert
.
assertTrue
(
message
.
contains
(
"限2030-03-29至2032-04-29日期内兑换"
),
"校验日期兑换限制失败"
);
Assert
.
assertEquals
(
exchangeText
,
"限2030-03-29至2032-04-29日期内兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制未开始成功"
);
break
;
case
2
:
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验日期兑换限制失败"
);
// Assert.assertTrue(message.contains("success"),"校验日期兑换限制失败");
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制进行中成功"
);
break
;
case
3
:
// Assert.assertEquals(response.jsonPath().getString("message"),"已结束","校验日期兑换限制失败");
Assert
.
assertTrue
(
message
.
contains
(
"限2019-03-27至2019-03-27日期内兑换"
),
"校验日期兑换限制失败"
);
Assert
.
assertEquals
(
exchangeText
,
"限2019-03-27至2019-03-27日期内兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制已结束成功"
);
break
;
}
}
@Test
public
void
会员等级测试
()
throws
Exception
{
String
appItemId
=
"194305"
;
String
message
=
""
;
//会员等级无法兑换
try
{
Response
response
=
gawService
.
virtualExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
81
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
//会员等级可兑换,vip=5
Response
response
=
gawService
.
virtualExchange
(
authorization
.
generateSignAutoLogin
(
"3tzVcss7SnAvA5ppT1m1rMPhaBcD"
,
7083
,
1
),
appItemId
,
81
);
response
.
prettyPrint
();
Assert
.
assertTrue
(
message
.
contains
(
"未达到会员等级要求"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验兑换结果失败"
);
logger
.
info
(
"校验实物会员等级成功"
);
}
@Test
public
void
用户周期限制消费测试
()
throws
Exception
{
String
appItemId
=
"193886"
;
try
{
//第一次兑换
Response
response
=
gawService
.
virtualExchange
(
cookie
,
appItemId
,
59
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"data.orderId"
);
//获取兑换结果
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
tawService
.
orderStatus
(
orderId
,
uid
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
cookie
,
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
gawService
.
virtualExchange
(
cookie
,
appItemId
,
59
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已达兑换次数上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户周期限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
}
}
}
src/test/java/http/cases/ExchangeTest/自有_商品兑换限制/自有老优惠券商品_兑换限制测试.java
0 → 100644
View file @
ecaac2d5
package
http
.
cases
.
ExchangeTest
.
自有
_
商品兑换限制
;
import
http.cases.ExchangeTest.CheckTemplet
;
import
http.service.Activity.ManagerService
;
import
http.service.Authorization
;
import
http.service.app.CouponExchangeService
;
import
http.service.app.MobileService
;
import
http.service.app.VirtualExchangeService
;
import
http.service.hd.DappConfigService
;
import
http.service.hd.DeveloperAccountService
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.DataProvider
;
import
org.testng.annotations.Test
;
import
utils.MatcherString
;
import
java.lang.reflect.Method
;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
io
.
restassured
.
RestAssured
.
given
;
/**
* Created by mabo on 2019/3/22
*/
public
class
自有老优惠券商品
_
兑换限制测试
extends
CheckTemplet
{
@Autowired
private
MobileService
mobileService
;
@Autowired
private
Authorization
authorization
;
@Autowired
private
CouponExchangeService
couponExchangeService
;
@Autowired
ManagerService
managerService
;
@Autowired
VirtualExchangeService
virtualExchangeService
;
@Autowired
DeveloperAccountService
developerAccountService
;
@Autowired
DappConfigService
dappConfigService
;
private
int
uid
=
7000
;
private
String
consumerId
=
"100144141"
;
private
String
url
=
"http://activity.m.duibatest.com.cn"
;
@BeforeMethod
public
void
beforeMethod
()
{
try
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record where consumer_id = ?"
,
consumerId
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only where consumer_id = ?"
,
consumerId
);
jdbc
.
update
(
"DELETE FROM goods.tb_everyday_limit where app_item_id=193825"
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@DataProvider
public
Object
[][]
providerMethod
(
Method
method
)
{
Object
[][]
result
=
null
;
if
(
method
.
getName
().
equals
(
"日期兑换限制测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
1
,
"193827"
,
"实物日期兑换限制未开始测试"
},
//case1
new
Object
[]{
2
,
"193828"
,
"实物日期兑换限制进行中测试"
},
//case2
new
Object
[]{
3
,
"193829"
,
"实物日期兑换限制已结束"
},
//case3
};
}
if
(
method
.
getName
().
equals
(
"库存不足测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
"193826"
,
"实物库存不足测试"
},
//case1
};
}
return
result
;
}
@Test
public
void
用户每日限制消费测试
()
throws
Exception
{
String
appItemId
=
"193822"
;
try
{
//第一次兑换
Response
response
=
couponExchangeService
.
couponExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
//获取兑换结果
response
=
mobileService
.
orderStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
couponExchangeService
.
couponExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"今日已达兑换上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已达兑换上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户每日限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
}
}
@Test
public
void
用户永久限制消费测试
()
throws
Exception
{
String
appItemId
=
"193823"
;
try
{
//第一次兑换
Response
response
=
couponExchangeService
.
couponExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
);
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
//获取兑换结果
response
=
mobileService
.
orderStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
couponExchangeService
.
couponExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已达兑换次数上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户永久限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '"+itemId+"'");
}
}
@Test
public
void
每日兑换上限测试
()
throws
Exception
{
String
appItemId
=
"193825"
;
try
{
//第一次兑换
Response
response
=
couponExchangeService
.
couponExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
);
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
//获取兑换结果
response
=
mobileService
.
orderStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
couponExchangeService
.
couponExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"今日已兑完,明天再来哦(14)"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"每日限量已兑完"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物每日兑换上限成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
//清掉每日兑换限制数据
// jdbc.update("DELETE FROM goods.tb_everyday_limit WHERE item_id = '"+itemId+"'");
}
}
/**
* @param appItemId 商品入库Id
* @param caseName 用例名称打印
* @throws Exception
*/
@Test
(
dataProvider
=
"providerMethod"
)
public
void
库存不足测试
(
String
appItemId
,
String
caseName
)
throws
Exception
{
logger
.
info
(
caseName
);
String
message
=
null
;
try
{
//兑换
Response
response
=
couponExchangeService
.
couponExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
);
}
catch
(
Exception
e
){
message
=
e
.
getMessage
();
logger
.
info
(
"message:"
+
message
);
}
//获取按钮状态
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"兑换按钮:"
+
exchangeText
);
Assert
.
assertTrue
(
message
.
contains
(
"今日已兑完,明天再来哦(14)"
),
"校验message失败"
);
Assert
.
assertEquals
(
exchangeText
,
"商品售罄"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物库存成功"
);
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param caseName 用例名称打印
* @throws Exception
*/
@Test
(
dataProvider
=
"providerMethod"
)
public
void
日期兑换限制测试
(
int
caseNum
,
String
appItemId
,
String
caseName
)
throws
Exception
{
logger
.
info
(
caseName
);
String
message
=
null
;
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"appItemId"
,
appItemId
);
Response
response
=
null
;
//兑换
try
{
response
=
couponExchangeService
.
couponExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
);
}
catch
(
Exception
e
){
message
=
e
.
getMessage
();
logger
.
info
(
"message:"
+
message
);
}
//获取按钮状态
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
switch
(
caseNum
){
case
1
:
// Assert.assertEquals(response.jsonPath().getString("message"),"请在限定时间内兑换哦(13)","校验日期兑换限制失败");
Assert
.
assertTrue
(
message
.
contains
(
"请在限定时间内兑换哦(13)"
),
"校验日期兑换限制失败"
);
Assert
.
assertEquals
(
exchangeText
,
"即将开始"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制未开始成功"
);
break
;
case
2
:
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验日期兑换限制失败"
);
// Assert.assertTrue(message.contains("success"),"校验日期兑换限制失败");
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制进行中成功"
);
break
;
case
3
:
// Assert.assertEquals(response.jsonPath().getString("message"),"已结束","校验日期兑换限制失败");
Assert
.
assertTrue
(
message
.
contains
(
"已结束"
),
"校验日期兑换限制失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已结束"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制已结束成功"
);
break
;
}
}
@Test
public
void
会员等级测试
()
throws
Exception
{
String
appItemId
=
"193821"
;
String
message
=
""
;
//会员等级无法兑换
try
{
Response
response
=
couponExchangeService
.
couponExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
//会员等级可兑换,vip=5
Response
response
=
couponExchangeService
.
couponExchange
(
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
3402
),
appItemId
,
null
);
response
.
prettyPrint
();
Assert
.
assertTrue
(
message
.
contains
(
"会员等级不符,请挑选其他吧(15)"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验兑换结果失败"
);
logger
.
info
(
"校验实物会员等级成功"
);
}
@Test
public
void
用户周期限制消费测试
()
throws
Exception
{
String
appItemId
=
"193824"
;
try
{
//第一次兑换
Response
response
=
couponExchangeService
.
couponExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
//获取兑换结果
response
=
mobileService
.
orderStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
couponExchangeService
.
couponExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已达兑换次数上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户周期限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
}
}
}
src/test/java/http/cases/ExchangeTest/自有_商品兑换限制/自有老实物_兑换限制测试.java
0 → 100644
View file @
ecaac2d5
package
http
.
cases
.
ExchangeTest
.
自有
_
商品兑换限制
;
import
http.cases.ExchangeTest.CheckTemplet
;
import
http.service.Activity.ManagerService
;
import
http.service.Authorization
;
import
http.service.app.CouponExchangeService
;
import
http.service.app.CrecordService
;
import
http.service.app.MobileService
;
import
http.service.app.VirtualExchangeService
;
import
http.service.hd.DappConfigService
;
import
http.service.hd.DeveloperAccountService
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.DataProvider
;
import
org.testng.annotations.Test
;
import
utils.MatcherString
;
import
java.lang.reflect.Method
;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
java.util.Map
;
import
static
io
.
restassured
.
RestAssured
.
given
;
/**
* Created by mabo on 2019/3/22
*/
public
class
自有老实物
_
兑换限制测试
extends
CheckTemplet
{
@Autowired
private
MobileService
mobileService
;
@Autowired
private
Authorization
authorization
;
@Autowired
private
CouponExchangeService
couponExchangeService
;
@Autowired
ManagerService
managerService
;
@Autowired
VirtualExchangeService
virtualExchangeService
;
@Autowired
DeveloperAccountService
developerAccountService
;
@Autowired
DappConfigService
dappConfigService
;
private
int
uid
=
6998
;
private
String
consumerId
=
"100144140"
;
private
String
url
=
"http://activity.m.duibatest.com.cn"
;
@BeforeMethod
public
void
beforeMethod
()
{
try
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record where consumer_id = ?"
,
consumerId
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only where consumer_id = ?"
,
consumerId
);
jdbc
.
update
(
"DELETE FROM goods.tb_everyday_limit where app_item_id=193815"
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@DataProvider
public
Object
[][]
providerMethod
(
Method
method
)
{
Object
[][]
result
=
null
;
if
(
method
.
getName
().
equals
(
"日期兑换限制测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
1
,
"193817"
,
"yrJRr7Cddp2YeQd"
,
"实物日期兑换限制未开始测试"
},
//case1
new
Object
[]{
2
,
"193818"
,
"yrJRr7Cddp2YeQd"
,
"实物日期兑换限制进行中测试"
},
//case2
new
Object
[]{
3
,
"193819"
,
"yrJRr7Cddp2YeQd"
,
"实物日期兑换限制已结束"
},
//case3
};
}
if
(
method
.
getName
().
equals
(
"库存不足测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
"193816"
,
"yrJRr7Cddp2YeQd"
,
"实物库存不足测试"
},
//case1
};
}
return
result
;
}
@Test
public
void
用户每日限制消费测试
()
throws
Exception
{
String
appItemId
=
"193812"
;
try
{
//第一次兑换
Response
response
=
couponExchangeService
.
objectExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
,
"null"
,
"yrJRr7Cddp2YeQd"
,
"null"
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
//获取兑换结果
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"data.message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"data.message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
couponExchangeService
.
objectExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
,
"null"
,
"yrJRr7Cddp2YeQd"
,
"null"
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"今日已达兑换上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已达兑换上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户每日限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
}
}
@Test
public
void
用户永久限制消费测试
()
throws
Exception
{
String
appItemId
=
"193813"
;
try
{
//第一次兑换
Response
response
=
couponExchangeService
.
objectExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
,
"null"
,
"yrJRr7Cddp2YeQd"
,
"null"
);
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
//获取兑换结果
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"data.message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"data.message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
couponExchangeService
.
objectExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
,
"null"
,
"yrJRr7Cddp2YeQd"
,
"null"
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已达兑换次数上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户永久限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '"+itemId+"'");
}
}
@Test
public
void
每日兑换上限测试
()
throws
Exception
{
String
appItemId
=
"193815"
;
try
{
//第一次兑换
Response
response
=
couponExchangeService
.
objectExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
,
"null"
,
"yrJRr7Cddp2YeQd"
,
"null"
);
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
//获取兑换结果
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"data.message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"data.message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
couponExchangeService
.
objectExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
appItemId
,
"null"
,
"yrJRr7Cddp2YeQd"
,
"null"
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"今日已兑完,明天再来哦(14)"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"每日限量已兑完"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物每日兑换上限成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
//清掉每日兑换限制数据
// jdbc.update("DELETE FROM goods.tb_everyday_limit WHERE item_id = '"+itemId+"'");
}
}
/**
* @param appItemId 商品入库Id
* @param token 活动token
* @param caseName 用例名称打印
* @throws Exception
*/
@Test
(
dataProvider
=
"providerMethod"
)
public
void
库存不足测试
(
String
appItemId
,
String
token
,
String
caseName
)
throws
Exception
{
logger
.
info
(
caseName
);
String
message
=
null
;
try
{
//兑换
Response
response
=
couponExchangeService
.
objectExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
,
"null"
,
"yrJRr7Cddp2YeQd"
,
"null"
);
}
catch
(
Exception
e
){
message
=
e
.
getMessage
();
logger
.
info
(
"message:"
+
message
);
}
//获取按钮状态
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"兑换按钮:"
+
exchangeText
);
Assert
.
assertTrue
(
message
.
contains
(
"今日已兑完,明天再来哦(14)"
),
"校验message失败"
);
Assert
.
assertEquals
(
exchangeText
,
"商品售罄"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物库存成功"
);
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param token 活动token
* @param caseName 用例名称打印
* @throws Exception
*/
@Test
(
dataProvider
=
"providerMethod"
)
public
void
日期兑换限制测试
(
int
caseNum
,
String
appItemId
,
String
token
,
String
caseName
)
throws
Exception
{
logger
.
info
(
caseName
);
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"appItemId"
,
appItemId
);
map
.
put
(
"token"
,
token
);
//兑换
Response
response
=
given
().
contentType
(
"application/x-www-form-urlencoded;charset=UTF-8"
).
cookies
(
authorization
.
dafuwengLogin
(
uid
)).
params
(
map
).
post
(
url
+
"/objectExchange/exchange"
);
response
.
prettyPrint
();
//获取按钮状态
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
switch
(
caseNum
){
case
1
:
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"message"
),
"请在限定时间内兑换哦(13)"
,
"校验日期兑换限制失败"
);
Assert
.
assertEquals
(
exchangeText
,
"即将开始"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制未开始成功"
);
break
;
case
2
:
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验日期兑换限制失败"
);
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制进行中成功"
);
break
;
case
3
:
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"message"
),
"已结束"
,
"校验日期兑换限制失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已结束"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制已结束成功"
);
break
;
}
}
@Test
public
void
会员等级测试
()
throws
Exception
{
String
appItemId
=
"193820"
;
String
message
=
""
;
//会员等级无法兑换
try
{
Response
response
=
couponExchangeService
.
objectExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
,
"null"
,
"yrJRr7Cddp2YeQd"
,
"null"
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
//会员等级可兑换,vip=5
Response
response
=
couponExchangeService
.
objectExchange
(
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
3402
),
appItemId
,
null
,
"null"
,
"yrJRr7Cddp2YeQd"
,
"null"
);
response
.
prettyPrint
();
Assert
.
assertTrue
(
message
.
contains
(
"会员等级不符,请挑选其他吧(15)"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验兑换结果失败"
);
logger
.
info
(
"校验实物会员等级成功"
);
}
@Test
public
void
用户周期限制消费测试
()
throws
Exception
{
String
appItemId
=
"193814"
;
try
{
//第一次兑换
Response
response
=
couponExchangeService
.
objectExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
,
"null"
,
"yrJRr7Cddp2YeQd"
,
"null"
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
//获取兑换结果
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"data.message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"data.message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
couponExchangeService
.
objectExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
null
,
"null"
,
"yrJRr7Cddp2YeQd"
,
"null"
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已达兑换次数上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户周期限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
}
}
}
src/test/java/http/cases/ExchangeTest/自有_商品兑换限制/自有老虚拟商品_兑换限制测试.java
0 → 100644
View file @
ecaac2d5
package
http
.
cases
.
ExchangeTest
.
自有
_
商品兑换限制
;
import
http.cases.ExchangeTest.CheckTemplet
;
import
http.service.Activity.ManagerService
;
import
http.service.Authorization
;
import
http.service.app.CouponExchangeService
;
import
http.service.app.MobileService
;
import
http.service.app.VirtualExchangeService
;
import
http.service.hd.DappConfigService
;
import
http.service.hd.DeveloperAccountService
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.DataProvider
;
import
org.testng.annotations.Test
;
import
utils.MatcherString
;
import
java.lang.reflect.Method
;
import
java.sql.SQLException
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* Created by mabo on 2019/3/25
*/
public
class
自有老虚拟商品
_
兑换限制测试
extends
CheckTemplet
{
@Autowired
private
MobileService
mobileService
;
@Autowired
private
Authorization
authorization
;
@Autowired
private
CouponExchangeService
couponExchangeService
;
@Autowired
ManagerService
managerService
;
@Autowired
VirtualExchangeService
virtualExchangeService
;
@Autowired
DeveloperAccountService
developerAccountService
;
@Autowired
DappConfigService
dappConfigService
;
private
int
uid
=
7002
;
private
String
consumerId
=
"100144144"
;
private
String
url
=
"http://activity.m.duibatest.com.cn"
;
@BeforeMethod
public
void
beforeMethod
()
{
try
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record where consumer_id = ?"
,
consumerId
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only where consumer_id = ?"
,
consumerId
);
jdbc
.
update
(
"DELETE FROM goods.tb_everyday_limit where app_item_id=193834"
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@DataProvider
public
Object
[][]
providerMethod
(
Method
method
)
{
Object
[][]
result
=
null
;
if
(
method
.
getName
().
equals
(
"日期兑换限制测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
1
,
"193836"
,
"实物日期兑换限制未开始测试"
},
//case1
new
Object
[]{
2
,
"193837"
,
"实物日期兑换限制进行中测试"
},
//case2
new
Object
[]{
3
,
"193838"
,
"实物日期兑换限制已结束"
},
//case3
};
}
if
(
method
.
getName
().
equals
(
"库存不足测试"
))
{
result
=
new
Object
[][]{
new
Object
[]{
"193835"
,
"实物库存不足测试"
},
//case1
};
}
return
result
;
}
@Test
public
void
用户每日限制消费测试
()
throws
Exception
{
String
appItemId
=
"193831"
;
try
{
//第一次兑换
Response
response
=
couponExchangeService
.
virtualExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
"123456"
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
//获取兑换结果
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
couponExchangeService
.
virtualExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
"123456"
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"今日已达兑换上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已达兑换上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户每日限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
}
}
@Test
public
void
用户永久限制消费测试
()
throws
Exception
{
String
appItemId
=
"193832"
;
try
{
//第一次兑换
Response
response
=
couponExchangeService
.
virtualExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
"123456"
);
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
//获取兑换结果
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
couponExchangeService
.
virtualExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
"123456"
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已达兑换次数上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户永久限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record_only WHERE item_id = '"+itemId+"'");
}
}
@Test
public
void
每日兑换上限测试
()
throws
Exception
{
String
appItemId
=
"193834"
;
try
{
//第一次兑换
Response
response
=
couponExchangeService
.
virtualExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
"123456"
);
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
//获取兑换结果
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
couponExchangeService
.
virtualExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
"123456"
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"今日已兑完,明天再来哦(14)"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"每日限量已兑完"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物每日兑换上限成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
//清掉每日兑换限制数据
// jdbc.update("DELETE FROM goods.tb_everyday_limit WHERE item_id = '"+itemId+"'");
}
}
/**
* @param appItemId 商品入库Id
* @param caseName 用例名称打印
* @throws Exception
*/
@Test
(
dataProvider
=
"providerMethod"
)
public
void
库存不足测试
(
String
appItemId
,
String
caseName
)
throws
Exception
{
logger
.
info
(
caseName
);
String
message
=
null
;
try
{
//兑换
Response
response
=
couponExchangeService
.
virtualExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
"123456"
);
}
catch
(
Exception
e
){
message
=
e
.
getMessage
();
logger
.
info
(
"message:"
+
message
);
}
//获取按钮状态
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"兑换按钮:"
+
exchangeText
);
Assert
.
assertTrue
(
message
.
contains
(
"今日已兑完,明天再来哦(14)"
),
"校验message失败"
);
Assert
.
assertEquals
(
exchangeText
,
"商品售罄"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物库存成功"
);
}
/**
* @param caseNum 用例编号
* @param appItemId 商品入库Id
* @param caseName 用例名称打印
* @throws Exception
*/
@Test
(
dataProvider
=
"providerMethod"
)
public
void
日期兑换限制测试
(
int
caseNum
,
String
appItemId
,
String
caseName
)
throws
Exception
{
logger
.
info
(
caseName
);
String
message
=
null
;
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"appItemId"
,
appItemId
);
Response
response
=
null
;
//兑换
try
{
response
=
couponExchangeService
.
virtualExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
"123456"
);
}
catch
(
Exception
e
){
message
=
e
.
getMessage
();
logger
.
info
(
"message:"
+
message
);
}
//获取按钮状态
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
switch
(
caseNum
){
case
1
:
// Assert.assertEquals(response.jsonPath().getString("message"),"请在限定时间内兑换哦(13)","校验日期兑换限制失败");
Assert
.
assertTrue
(
message
.
contains
(
"请在限定时间内兑换哦(13)"
),
"校验日期兑换限制失败"
);
Assert
.
assertEquals
(
exchangeText
,
"即将开始"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制未开始成功"
);
break
;
case
2
:
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验日期兑换限制失败"
);
// Assert.assertTrue(message.contains("success"),"校验日期兑换限制失败");
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制进行中成功"
);
break
;
case
3
:
// Assert.assertEquals(response.jsonPath().getString("message"),"已结束","校验日期兑换限制失败");
Assert
.
assertTrue
(
message
.
contains
(
"已结束"
),
"校验日期兑换限制失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已结束"
,
"校验马上兑换按钮状态失败"
);
logger
.
info
(
"校验实物日期兑换限制已结束成功"
);
break
;
}
}
@Test
public
void
会员等级测试
()
throws
Exception
{
String
appItemId
=
"193830"
;
String
message
=
""
;
//会员等级无法兑换
try
{
Response
response
=
couponExchangeService
.
virtualExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
"123456"
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
//会员等级可兑换,vip=5
Response
response
=
couponExchangeService
.
virtualExchange
(
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
3402
),
appItemId
,
"123456"
);
response
.
prettyPrint
();
Assert
.
assertTrue
(
message
.
contains
(
"会员等级不符,请挑选其他吧(15)"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
,
"校验兑换结果失败"
);
logger
.
info
(
"校验实物会员等级成功"
);
}
@Test
public
void
用户周期限制消费测试
()
throws
Exception
{
String
appItemId
=
"193833"
;
try
{
//第一次兑换
Response
response
=
couponExchangeService
.
virtualExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
"123456"
);
response
.
prettyPrint
();
String
orderId
=
response
.
jsonPath
().
getString
(
"orderId"
);
//获取兑换结果
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
String
message
=
response
.
jsonPath
().
getString
(
"message"
);
int
i
=
10
;
//异步接口,直到兑换成功
while
(
i
>
0
&&
"兑换正在处理中..."
.
equals
(
message
))
{
Thread
.
sleep
(
1000
);
response
=
mobileService
.
orderAmbStatusQuery
(
uid
,
orderId
);
response
.
prettyPrint
();
message
=
response
.
jsonPath
().
getString
(
"message"
);
i
--;
}
Response
detailResponse
=
mobileService
.
appItemDetail
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
);
detailResponse
.
prettyPrint
();
String
exchangeText
=
MatcherString
.
getString
(
detailResponse
.
asString
(),
"\"exchangeText\":\"(.*?)\","
,
1
);
logger
.
info
(
"商品兑换按钮:"
+
exchangeText
);
//第二次兑换
Thread
.
sleep
(
3000
);
try
{
response
=
couponExchangeService
.
virtualExchange
(
authorization
.
dafuwengLogin
(
uid
),
appItemId
,
"123456"
);
response
.
prettyPrint
();
}
catch
(
Exception
e
){
message
=
e
.
toString
();
}
logger
.
info
(
message
);
Assert
.
assertTrue
(
message
.
contains
(
"已达兑换次数上限"
),
"校验message失败"
);
Assert
.
assertTrue
(
message
.
contains
(
"\"success\":false"
),
"校验success失败"
);
Assert
.
assertEquals
(
exchangeText
,
"已达兑换次数上限"
,
"校验兑换按钮失败"
);
logger
.
info
(
"校验实物用户周期限制消费成功"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"异常信息打印:"
+
e
);
}
finally
{
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record WHERE item_id = '"+itemId+"'");
}
}
}
src/test/java/http/cases/SeckillTest/秒杀自有老优惠券_兑换限制_SeckillTest.java
0 → 100644
View file @
ecaac2d5
package
http
.
cases
.
SeckillTest
;
import
base.DuibaTestBase
;
import
http.service.Authorization
;
import
http.service.app.SeckillService
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.Test
;
import
utils.MatcherString
;
import
java.sql.SQLException
;
/**
* Created by mabo on 2019/3/15
*/
public
class
秒杀自有老优惠券
_
兑换限制
_SeckillTest
extends
DuibaTestBase
{
//app 13193333111
@Autowired
SeckillService
seckillService
;
@Autowired
Authorization
authorization
;
public
static
int
uid
=
6590
;
@BeforeMethod
public
void
beforeMethod
()
{
try
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record where consumer_id = 100143018"
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only where consumer_id = 100143018"
);
jdbc
.
update
(
"DELETE FROM goods.tb_everyday_limit where app_item_id=191791"
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
每人每日兑换限制
()
throws
InterruptedException
{
Response
response
=
seckillService
.
exchange2
(
"191788"
,
"undefined"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
Thread
.
sleep
(
10000
);
response
=
seckillService
.
queryBtnStatus
(
"191788"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已兑换"
);
}
@Test
public
void
每人永久兑换限制
()
throws
InterruptedException
{
Response
response
=
seckillService
.
exchange2
(
"191789"
,
"undefined"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
Thread
.
sleep
(
10000
);
String
orderId
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"orderId: '(.*?)'"
,
1
);
response
=
seckillService
.
queryBtnStatus
(
"191789"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"已兑换"
);
}
@Test
public
void
每人周期兑换限制
()
throws
InterruptedException
{
Response
response
=
seckillService
.
queryBtnStatus
(
"191790"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
);
response
=
seckillService
.
exchange2
(
"191790"
,
"undefined"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
Thread
.
sleep
(
10000
);
response
=
seckillService
.
queryBtnStatus
(
"191790"
,
uid
);
response
.
prettyPrint
();
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"已兑换"
);
response
=
seckillService
.
exchange2
(
"191790"
,
"undefined"
,
uid
);
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
10000
);
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
String
result
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<h2 class=\"tit\">(.*?)</h2>"
,
1
);
Assert
.
assertEquals
(
result
,
"好可惜,没抢到"
);
}
@Test
public
void
商品兑换限制
()
throws
InterruptedException
{
Response
response
=
seckillService
.
queryBtnStatus
(
"191791"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
);
response
=
seckillService
.
exchange2
(
"191791"
,
"undefined"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
10000
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
response
=
seckillService
.
queryBtnStatus
(
"191791"
,
uid
);
response
.
prettyPrint
();
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已兑完"
);
}
@Test
public
void
无库存
()
throws
SQLException
,
InterruptedException
{
jdbc
.
update
(
"UPDATE stock.tb_stock set stock = 1 where stock_id = \"933147340081120308\""
);
jdbc
.
update
(
"update goods.tb_goods_batch set status =2 where gid = 191796"
);
Response
response
=
seckillService
.
queryBtnStatus
(
"191796"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
int
i
=
50
;
while
(
i
>
0
&&
exchangeText
.
equals
(
"已兑完"
)){
Thread
.
sleep
(
3000
);
response
=
seckillService
.
queryBtnStatus
(
"191796"
,
uid
);
response
.
prettyPrint
();
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
System
.
out
.
println
(
i
);
i
--;
}
response
=
seckillService
.
exchange2
(
"191796"
,
"undefined"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
10000
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
Assert
.
assertEquals
(
MatcherString
.
getString
(
queryResponse
.
asString
(),
"\"kind\":\"(.*?)\","
,
1
),
"success"
,
"校验kind失败"
);
response
=
seckillService
.
exchange2
(
"191796"
,
"undefined"
,
uid
);
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
15000
);
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
Assert
.
assertEquals
(
MatcherString
.
getString
(
queryResponse
.
asString
(),
"\"kind\":\"(.*?)\","
,
1
),
"fail"
,
"校验kind失败"
);
response
=
seckillService
.
queryBtnStatus
(
"191796"
,
uid
);
response
.
prettyPrint
();
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
i
=
10
;
while
(
i
>
0
&&!
exchangeText
.
equals
(
"已兑完"
)){
Thread
.
sleep
(
3000
);
response
=
seckillService
.
queryBtnStatus
(
"191796"
,
uid
);
response
.
prettyPrint
();
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
System
.
out
.
println
(
i
);
i
--;
}
Assert
.
assertEquals
(
exchangeText
,
"已兑完"
);
jdbc
.
update
(
"UPDATE stock.tb_stock set stock = 1 where stock_id = \"933147340081120308\""
);
jdbc
.
update
(
"update goods.tb_goods_batch set status =2 where gid = 191796"
);
}
@Test
public
void
vip
限制
()
throws
InterruptedException
{
//未达到等级,不可秒杀
Response
response
=
seckillService
.
queryBtnStatus
(
"193754"
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
0
));
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.vipLimitViewInfoVO.isCanConsumerExchange"
);
Assert
.
assertEquals
(
exchangeText
,
"false"
);
response
=
seckillService
.
exchange2
(
"193754"
,
"undefined"
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
0
));
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
5000
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
0
));
queryResponse
.
prettyPrint
();
String
title
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<h2 class=\"tit\">(.*?)</h2>"
,
1
);
Assert
.
assertEquals
(
title
,
"好可惜,没抢到"
);
//达到等级,可秒杀
response
=
seckillService
.
queryBtnStatus
(
"193754"
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
1
));
response
.
prettyPrint
();
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.vipLimitViewInfoVO.isCanConsumerExchange"
);
Assert
.
assertEquals
(
exchangeText
,
"true"
);
response
=
seckillService
.
exchange2
(
"193754"
,
"undefined"
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
1
));
response
.
prettyPrint
();
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
5000
);
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
1
));
queryResponse
.
prettyPrint
();
String
kind
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"\"kind\":\"(.*?)\","
,
1
);
Assert
.
assertEquals
(
kind
,
"success"
);
}
}
src/test/java/http/cases/SeckillTest/秒杀自有老实物_兑换限制.java
deleted
100644 → 0
View file @
399aed5e
package
http
.
cases
.
SeckillTest
;
import
base.DuibaTestBase
;
import
http.service.app.SeckillService
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.Test
;
import
java.sql.SQLException
;
/**
* Created by mabo on 2019/3/13
*/
public
class
秒杀自有老实物
_
兑换限制
extends
DuibaTestBase
{
@Autowired
SeckillService
seckillService
;
public
static
int
uid
=
6554
;
// @BeforeMethod
// public void beforeMethod() {
// try {
// jdbc.update("DELETE FROM credits_dev.consumer_limit_record where item_id=191783 and consumer_id = 100137015");
// } catch (SQLException e) {
// e.printStackTrace();
// }
//
//
// }
// @Test
public
void
每人每日兑换限制
(){
Response
response
=
seckillService
.
exchange1
(
"191783"
,
"undefined"
,
uid
);
response
.
prettyPrint
();
response
=
seckillService
.
exchange1
(
"191783"
,
"undefined"
,
uid
);
response
.
prettyPrint
();
}
}
src/test/java/http/cases/SeckillTest/秒杀自有老实物_兑换限制_SeckillTest.java
0 → 100644
View file @
ecaac2d5
package
http
.
cases
.
SeckillTest
;
import
base.DuibaTestBase
;
import
http.service.Authorization
;
import
http.service.app.SeckillService
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.Test
;
import
utils.MatcherString
;
import
java.sql.SQLException
;
/**
* Created by mabo on 2019/3/13
*/
public
class
秒杀自有老实物
_
兑换限制
_SeckillTest
extends
DuibaTestBase
{
//app 13193333111
@Autowired
SeckillService
seckillService
;
@Autowired
Authorization
authorization
;
public
static
int
uid
=
6575
;
@BeforeMethod
public
void
beforeMethod
()
{
try
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record where consumer_id = 100139002"
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only where consumer_id = 100139002"
);
jdbc
.
update
(
"DELETE FROM goods.tb_everyday_limit where app_item_id=191786"
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
每人每日兑换限制
()
throws
InterruptedException
{
Response
response
=
seckillService
.
exchange2
(
"191783"
,
"undefined"
,
uid
);
// response.prettyPrint();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
// queryResponse.prettyPrint();
Thread
.
sleep
(
10000
);
response
=
seckillService
.
queryBtnStatus
(
"191783"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
//校验按钮转台
Assert
.
assertEquals
(
exchangeText
,
"今日已兑换"
);
}
@Test
public
void
每人永久兑换限制
()
throws
InterruptedException
{
Response
response
=
seckillService
.
exchange2
(
"191784"
,
"undefined"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
10000
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
String
orderId
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"orderId: '(.*?)'"
,
1
);
response
=
seckillService
.
queryBtnStatus
(
"191784"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"已兑换"
);
}
@Test
public
void
每人周期兑换限制
()
throws
InterruptedException
{
Response
response
=
seckillService
.
queryBtnStatus
(
"191785"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
);
response
=
seckillService
.
exchange2
(
"191785"
,
"undefined"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
10000
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
response
=
seckillService
.
queryBtnStatus
(
"191785"
,
uid
);
response
.
prettyPrint
();
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"已兑换"
);
}
@Test
public
void
商品兑换限制
()
throws
InterruptedException
{
Response
response
=
seckillService
.
queryBtnStatus
(
"191786"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
);
response
=
seckillService
.
exchange2
(
"191786"
,
"undefined"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
10000
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
response
=
seckillService
.
queryBtnStatus
(
"191786"
,
uid
);
response
.
prettyPrint
();
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已兑完"
);
}
@Test
public
void
无库存
()
throws
SQLException
,
InterruptedException
{
jdbc
.
update
(
"UPDATE stock.tb_stock set stock = 1 where stock_id = \"933059354152870299\""
);
Response
response
=
seckillService
.
exchange2
(
"191787"
,
"undefined"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
Thread
.
sleep
(
10000
);
response
=
seckillService
.
queryBtnStatus
(
"191787"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
response
=
seckillService
.
exchange2
(
"191787"
,
"undefined"
,
uid
);
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
10000
);
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
String
orderId
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"orderId: '(.*?)'"
,
1
);
String
result
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<h2 class=\"tit\">(.*?)</h2>"
,
1
);
response
=
seckillService
.
detail
(
orderId
,
uid
);
response
.
prettyPrint
();
String
failedReason
=
response
.
jsonPath
().
getString
(
"data.failedReason"
);
Assert
.
assertEquals
(
failedReason
,
"库存不足"
);
}
@Test
public
void
vip
限制
()
throws
InterruptedException
{
//未达到等级不可兑换
Response
response
=
seckillService
.
queryBtnStatus
(
"193753"
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
0
));
// response.prettyPrint();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.vipLimitViewInfoVO.isCanConsumerExchange"
);
Assert
.
assertEquals
(
exchangeText
,
"false"
);
response
=
seckillService
.
exchange2
(
"193753"
,
"undefined"
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
0
));
// response.prettyPrint();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
5000
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
0
));
// queryResponse.prettyPrint();
String
title
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<h2 class=\"tit\">(.*?)</h2>"
,
1
);
Assert
.
assertEquals
(
title
,
"好可惜,没抢到"
);
//达到等级可兑换
response
=
seckillService
.
queryBtnStatus
(
"193753"
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
1
));
// response.prettyPrint();
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.vipLimitViewInfoVO.isCanConsumerExchange"
);
Assert
.
assertEquals
(
exchangeText
,
"true"
);
response
=
seckillService
.
exchange2
(
"193753"
,
"undefined"
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
1
));
// response.prettyPrint();
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
5000
);
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
1
));
// queryResponse.prettyPrint();
String
orderId
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"orderId: '(.*?)'"
,
1
);
response
=
seckillService
.
detail
(
orderId
,
uid
);
// response.prettyPrint();
String
statusText
=
response
.
jsonPath
().
getString
(
"data.statusText"
);
Assert
.
assertEquals
(
statusText
,
"等待商家发货"
);
}
}
src/test/java/http/cases/SeckillTest/秒杀自有老虚拟商品_兑换限制_SeckillTest.java
0 → 100644
View file @
ecaac2d5
package
http
.
cases
.
SeckillTest
;
import
base.DuibaTestBase
;
import
http.service.Authorization
;
import
http.service.app.SeckillService
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.Test
;
import
utils.MatcherString
;
import
java.sql.SQLException
;
/**
* Created by mabo on 2019/3/15
*/
public
class
秒杀自有老虚拟商品
_
兑换限制
_SeckillTest
extends
DuibaTestBase
{
//app 13193333111
@Autowired
SeckillService
seckillService
;
@Autowired
Authorization
authorization
;
public
static
int
uid
=
6591
;
@BeforeMethod
public
void
beforeMethod
()
{
try
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record where consumer_id = 100143033"
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only where consumer_id = 100143033"
);
jdbc
.
update
(
"DELETE FROM goods.tb_everyday_limit where app_item_id=192019"
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
@Test
public
void
每人每日兑换限制
()
throws
InterruptedException
{
Response
response
=
seckillService
.
exchange3
(
"191797"
,
"123"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
Thread
.
sleep
(
10000
);
response
=
seckillService
.
queryBtnStatus
(
"191797"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已兑换"
);
}
@Test
public
void
每人永久兑换限制
()
throws
InterruptedException
{
Response
response
=
seckillService
.
exchange3
(
"191987"
,
"123456"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
Thread
.
sleep
(
10000
);
String
orderId
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"orderId: '(.*?)'"
,
1
);
response
=
seckillService
.
queryBtnStatus
(
"191987"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"已兑换"
);
}
@Test
public
void
每人周期兑换限制
()
throws
InterruptedException
{
Response
response
=
seckillService
.
queryBtnStatus
(
"192003"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
);
response
=
seckillService
.
exchange2
(
"192003"
,
"undefined"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
Thread
.
sleep
(
10000
);
response
=
seckillService
.
queryBtnStatus
(
"192003"
,
uid
);
response
.
prettyPrint
();
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"已兑换"
);
response
=
seckillService
.
exchange2
(
"192003"
,
"undefined"
,
uid
);
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
10000
);
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
String
orderId
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"orderId: '(.*?)'"
,
1
);
String
result
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<h2 class=\"tit\">(.*?)</h2>"
,
1
);
Assert
.
assertEquals
(
result
,
"好可惜,没抢到"
);
}
@Test
public
void
商品兑换限制
()
throws
InterruptedException
{
Response
response
=
seckillService
.
queryBtnStatus
(
"192019"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
);
response
=
seckillService
.
exchange3
(
"192019"
,
"123456"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
10000
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
response
=
seckillService
.
queryBtnStatus
(
"192019"
,
uid
);
response
.
prettyPrint
();
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已兑完"
);
}
@Test
public
void
无库存
()
throws
SQLException
,
InterruptedException
{
//更新数据库库存为1
jdbc
.
update
(
"UPDATE stock.tb_stock set stock = 1 where stock_id = \"934806710018620543\""
);
//第一次秒杀
Response
response
=
seckillService
.
exchange3
(
"192031"
,
"123456"
,
uid
);
//获取队列id
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
10000
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
response
=
seckillService
.
queryBtnStatus
(
"192031"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
// Assert.assertEquals(exchangeText,"已兑完");
response
=
seckillService
.
exchange3
(
"192031"
,
"123456"
,
uid
);
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
10000
);
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
String
orderId
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"orderId: '(.*?)'"
,
1
);
String
result
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<h2 class=\"tit\">(.*?)</h2>"
,
1
);
response
=
seckillService
.
detail
(
orderId
,
uid
);
response
.
prettyPrint
();
String
failedReason
=
response
.
jsonPath
().
getString
(
"data.failedReason"
);
Assert
.
assertEquals
(
failedReason
,
"库存不足"
);
}
@Test
public
void
vip
限制
()
throws
InterruptedException
{
//未达到会员等级,不可秒杀
Response
response
=
seckillService
.
queryBtnStatus
(
"193755"
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
0
));
// response.prettyPrint();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.vipLimitViewInfoVO.isCanConsumerExchange"
);
Assert
.
assertEquals
(
exchangeText
,
"false"
);
response
=
seckillService
.
exchange3
(
"193755"
,
"123456"
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
0
));
// response.prettyPrint();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
5000
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
0
));
// queryResponse.prettyPrint();
String
title
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<h2 class=\"tit\">(.*?)</h2>"
,
1
);
Assert
.
assertEquals
(
title
,
"好可惜,没抢到"
);
//达到会员等级,可兑换
response
=
seckillService
.
queryBtnStatus
(
"193755"
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
1
));
// response.prettyPrint();
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.vipLimitViewInfoVO.isCanConsumerExchange"
);
Assert
.
assertEquals
(
exchangeText
,
"true"
);
response
=
seckillService
.
exchange3
(
"193755"
,
"123456"
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
1
));
// response.prettyPrint();
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
5000
);
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
authorization
.
generateSignAutoLogin
(
"2wGQc3MZaQsqYFWcX4gguya5PnnS"
,
uid
,
1
));
// queryResponse.prettyPrint();
String
orderId
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"orderId: '(.*?)'"
,
1
);
response
=
seckillService
.
detail
(
orderId
,
uid
);
// response.prettyPrint();
String
status
=
response
.
jsonPath
().
getString
(
"data.status"
);
Assert
.
assertEquals
(
status
,
"success"
);
}
}
src/test/java/http/cases/SeckillTest/秒杀话费_兑换限制_SeckillTest.java
0 → 100644
View file @
ecaac2d5
package
http
.
cases
.
SeckillTest
;
import
base.DuibaTestBase
;
import
com.alibaba.fastjson.JSON
;
import
http.service.Authorization
;
import
http.service.app.SeckillService
;
import
io.restassured.response.Response
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeMethod
;
import
org.testng.annotations.Test
;
import
utils.MatcherString
;
import
java.sql.SQLException
;
/**
* Created by mabo on 2019/3/20
*/
public
class
秒杀话费
_
兑换限制
_SeckillTest
extends
DuibaTestBase
{
//app 13193333111
@Autowired
SeckillService
seckillService
;
@Autowired
Authorization
authorization
;
@BeforeMethod
public
void
beforeMethod
()
{
try
{
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record where consumer_id = 100143514"
);
jdbc
.
update
(
"DELETE FROM credits_dev.consumer_limit_record_only where consumer_id = 100143514"
);
jdbc
.
update
(
"DELETE FROM goods.tb_everyday_limit where app_item_id=193206"
);
}
catch
(
SQLException
e
)
{
e
.
printStackTrace
();
}
}
public
static
int
uid
=
6865
;
@Test
public
void
每日兑换限制
()
throws
InterruptedException
{
Response
response
=
seckillService
.
exchange4
(
"193206"
,
"1660"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
10000
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
Assert
.
assertEquals
(
MatcherString
.
getString
(
queryResponse
.
asString
(),
"\"kind\":\"(.*?)\","
,
1
),
"success"
,
"校验kind失败"
);
response
=
seckillService
.
queryBtnStatus
(
"193206"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已兑完"
);
}
@Test
public
void
用户兑换限制
_
每天
()
throws
InterruptedException
{
Response
response
=
seckillService
.
exchange4
(
"193209"
,
"1662"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
String
kind
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"\"kind\":\"(.*?)\","
,
1
);
String
title
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<title>(.*?)</title>"
,
1
);
int
i
=
20
;
while
(
i
>
0
&&(
"process"
.
equals
(
kind
)||(
title
.
equals
(
"等待中"
)))){
Thread
.
sleep
(
3000
);
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
kind
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"\"kind\":\"(.*?)\","
,
1
);
title
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<title>(.*?)</title>"
,
1
);
i
--;
}
Assert
.
assertEquals
(
MatcherString
.
getString
(
queryResponse
.
asString
(),
"\"kind\":\"(.*?)\","
,
1
),
"success"
,
"校验kind失败"
);
response
=
seckillService
.
queryBtnStatus
(
"193209"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"今日已兑换"
);
}
@Test
public
void
用户兑换限制
_
永久
()
throws
InterruptedException
{
Response
response
=
seckillService
.
exchange4
(
"193208"
,
"1661"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
String
kind
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"\"kind\":\"(.*?)\","
,
1
);
String
title
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<title>(.*?)</title>"
,
1
);
int
i
=
20
;
while
(
i
>
0
&&(
"process"
.
equals
(
kind
)||(
title
.
equals
(
"等待中"
)))){
Thread
.
sleep
(
3000
);
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
kind
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"\"kind\":\"(.*?)\","
,
1
);
title
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<title>(.*?)</title>"
,
1
);
i
--;
}
Assert
.
assertEquals
(
MatcherString
.
getString
(
queryResponse
.
asString
(),
"\"kind\":\"(.*?)\","
,
1
),
"success"
,
"校验kind失败"
);
response
=
seckillService
.
queryBtnStatus
(
"193208"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"已兑换"
);
}
@Test
public
void
日期兑换限制
_
已过期
()
throws
InterruptedException
{
Response
response
=
seckillService
.
queryBtnStatus
(
"193211"
,
uid
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"已结束"
);
response
=
seckillService
.
exchange4
(
"193211"
,
"1664"
,
uid
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
String
title
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<title>(.*?)</title>"
,
1
);
for
(
int
i
=
36
;
i
>
0
;
i
--){
if
(
title
.
equals
(
"等待中"
)){
Thread
.
sleep
(
3000
);
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uid
);
queryResponse
.
prettyPrint
();
}
}
logger
.
info
(
"queueId="
+
queueId
+
",queryResponse的信息为"
+
JSON
.
toJSONString
(
queryResponse
));
Assert
.
assertEquals
(
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<h2 class=\"tit\">(.*?)</h2>"
,
1
),
"好可惜,没抢到"
,
"文案校验失败"
);
}
@Test
public
void
日期兑换限制
_
日期内
()
throws
InterruptedException
{
//app 13193333112
int
uids
=
6937
;
Response
response
=
seckillService
.
queryBtnStatus
(
"193449"
,
uids
);
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.exchangeBtnVO.exchangeText"
);
Assert
.
assertEquals
(
exchangeText
,
"马上兑换"
);
response
=
seckillService
.
exchange4
(
"193449"
,
"1660"
,
uids
);
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uids
);
queryResponse
.
prettyPrint
();
String
kind
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"\"kind\":\"(.*?)\","
,
1
);
String
title
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<title>(.*?)</title>"
,
1
);
int
i
=
20
;
while
(
i
>
0
&&(
"process"
.
equals
(
kind
)||(
title
.
equals
(
"等待中"
)))){
Thread
.
sleep
(
3000
);
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
uids
);
queryResponse
.
prettyPrint
();
kind
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"\"kind\":\"(.*?)\","
,
1
);
title
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<title>(.*?)</title>"
,
1
);
i
--;
}
Assert
.
assertEquals
(
MatcherString
.
getString
(
queryResponse
.
asString
(),
"\"kind\":\"(.*?)\","
,
1
),
"success"
,
"校验kind失败"
);
}
@Test
public
void
vip
限制
()
throws
InterruptedException
{
//app 13193333112
int
uids
=
6937
;
Response
response
=
seckillService
.
queryBtnStatus
(
"193451"
,
authorization
.
generateSignAutoLogin
(
"ZQyvfB6a47hpRnfyhggtkcs4KQS"
,
uids
,
0
));
response
.
prettyPrint
();
String
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.vipLimitViewInfoVO.isCanConsumerExchange"
);
Assert
.
assertEquals
(
exchangeText
,
"false"
);
// Assert.assertEquals(exchangeText,"马上兑换");
response
=
seckillService
.
exchange4
(
"193451"
,
"1661"
,
authorization
.
generateSignAutoLogin
(
"ZQyvfB6a47hpRnfyhggtkcs4KQS"
,
uids
,
0
));
response
.
prettyPrint
();
String
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
5000
);
Response
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
authorization
.
generateSignAutoLogin
(
"ZQyvfB6a47hpRnfyhggtkcs4KQS"
,
uids
,
0
));
queryResponse
.
prettyPrint
();
String
title
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<h2 class=\"tit\">(.*?)</h2>"
,
1
);
Assert
.
assertEquals
(
title
,
"好可惜,没抢到"
);
response
=
seckillService
.
queryBtnStatus
(
"193451"
,
authorization
.
generateSignAutoLogin
(
"ZQyvfB6a47hpRnfyhggtkcs4KQS"
,
uids
,
1
));
response
.
prettyPrint
();
exchangeText
=
response
.
jsonPath
().
getString
(
"data.seckillBtnVO.vipLimitViewInfoVO.isCanConsumerExchange"
);
Assert
.
assertEquals
(
exchangeText
,
"true"
);
response
=
seckillService
.
exchange4
(
"193451"
,
"1661"
,
authorization
.
generateSignAutoLogin
(
"ZQyvfB6a47hpRnfyhggtkcs4KQS"
,
uids
,
1
));
response
.
prettyPrint
();
queueId
=
response
.
jsonPath
().
getString
(
"data.queueId"
);
Thread
.
sleep
(
5000
);
queryResponse
=
seckillService
.
queueQuery
(
queueId
,
authorization
.
generateSignAutoLogin
(
"ZQyvfB6a47hpRnfyhggtkcs4KQS"
,
uids
,
1
));
queryResponse
.
prettyPrint
();
String
kind
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"\"kind\":\"(.*?)\","
,
1
);
title
=
MatcherString
.
getString
(
queryResponse
.
asString
(),
"<h2 class=\"tit\">(.*?)</h2>"
,
1
);
}
}
src/test/java/http/service/Authorization.java
View file @
ecaac2d5
...
...
@@ -197,6 +197,15 @@ public class Authorization {
}
public
Map
generateSignAutoLogin
(
String
appKey
,
int
uid
,
int
vip
){
String
url
=
"http://activity.m.duibatest.com.cn/test/generateSign?appKey="
+
appKey
+
"&uid="
+
uid
+
"&vip="
+
vip
;
Response
response
=
given
().
get
(
url
);
url
=
response
.
jsonPath
().
get
(
"url"
);
response
=
given
().
redirects
().
follow
(
false
).
get
(
url
);
return
response
.
getCookies
();
}
//开发者后台登录
public
Map
hdLogin
(){
...
...
src/test/java/http/service/app/CouponExchangeService.java
View file @
ecaac2d5
...
...
@@ -249,6 +249,37 @@ public class CouponExchangeService {
}
/**
* 虚拟商品兑换接口
* @param cookies
* @param appItemId
* @param degreeId
* @return
* @throws Exception
*/
public
Response
virtualExchange
(
Map
cookies
,
String
appItemId
,
String
degreeId
)
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"appItemId"
,
appItemId
);
map
.
put
(
"degreeId"
,
degreeId
);
map
.
put
(
"token"
,
"yrJRr7Cddp2YeQd"
);
logger
.
info
(
"请求/virtualExchange/exchange接口"
);
Response
response
=
given
().
contentType
(
"application/x-www-form-urlencoded;charset=UTF-8"
).
cookies
(
cookies
).
params
(
map
).
post
(
"http://"
+
goodsHost
+
"/virtualExchange/exchange"
);
//couponExchange
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"/virtualExchange/exchange接口返回异常,返回信息:"
+
response
.
asString
());
}
catch
(
Error
er
){
throw
new
Exception
(
"/virtualExchange/exchange接口返回异常,返回信息:"
+
response
.
asString
());
}
return
response
;
}
public
Response
objectExchange
(
String
appItemId
,
String
itemId
)
throws
Exception
{
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"appItemId"
,
appItemId
);
...
...
src/test/java/http/service/app/SeckillService.java
View file @
ecaac2d5
...
...
@@ -81,6 +81,28 @@ public class SeckillService {
}
return
response
;
}
public
Response
queryBtnStatus
(
String
appItemId
,
Map
cookie
)
{
String
url
=
"http://"
+
seckillHost
+
"/appItemSecKill/queryBtnStatus"
;
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"appItemId"
,
appItemId
);
Response
response
=
given
().
cookies
(
cookie
).
params
(
map
).
get
(
url
);
try
{
int
i
=
8
;
while
((!
checkNomal
(
"queryBtnStatus"
,
response
))&&
i
>
0
){
Thread
.
sleep
(
1000
);
response
=
given
().
cookies
(
cookie
).
params
(
map
).
get
(
url
);
response
.
prettyPrint
();
i
--;
}
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
return
response
;
}
public
Response
queryBtnStatus2
(
String
appItemId
)
{
...
...
@@ -139,6 +161,84 @@ public class SeckillService {
return
response
;
}
public
Response
exchange2
(
String
appItemId
,
String
itemId
,
Map
cookie
)
{
String
url
=
"http://"
+
seckillHost
+
"/appItemSecKill/exchange"
;
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"validate"
,
"kwExo7h9lQwLWM0x87uYeYrLtFO9L16IIB22qqBi5o97ema7Ut0uOuSg5tD6tH5DFDIGFBFadR2pFEGsr9oR-wvieKqnTAUlJyuGPx_sSBHfcNWw4loVj6hXPV2IP04PrvfS15JIt7leklEfnmtEPAqrZmGx7jW5UAA2CzNvbXgEM-kGqGARuVFTnjG8_RwjkLBibXEHCGXhKZ8H7LMLo10C0nvyIHqWhVBdeWjuZl66bFYP8W0qbbwzzRNbobdx0_x59LecepmzNO2PdG4QPb9n4OYVQgSDTj.Nw0qizpZKcAWf0xnJeegXgVf66o_rZrZUHmSn2pgoz4qcZeSG0yekGMnng8Ak9YUvUhprowTpGT.DV8rs4Dw6Et2l1jUfkI7c4qaBKBbZbzaNvZzK5UvbpaaVFGtV2Kg.H_MrwgwBJjWiWNdds2K68aXYb6cpjtE6JwfIxiYu57TeZD9LUI_jJCq0BD0XPn5f6Q-MiudOLJX4EEdIBqQRl4r3"
);
map
.
put
(
"appItemId"
,
appItemId
);
map
.
put
(
"itemId"
,
itemId
);
map
.
put
(
"addrName"
,
"qianwenjun"
);
map
.
put
(
"addrPhone"
,
"18143476362"
);
map
.
put
(
"addrProvince"
,
"浙江省"
);
map
.
put
(
"addrCity"
,
"杭州市"
);
map
.
put
(
"addrArea"
,
"西湖区"
);
map
.
put
(
"addrDetail"
,
"数娱大厦"
);
Response
response
=
given
().
cookies
(
cookie
).
params
(
map
).
get
(
url
);
return
response
;
}
//虚拟商品
public
Response
exchange3
(
String
appItemId
,
String
degreeId
,
int
uid
)
{
String
url
=
"http://"
+
seckillHost
+
"/appItemSecKill/exchange"
;
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"appItemId"
,
appItemId
);
map
.
put
(
"degreeId"
,
degreeId
);
Response
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
uid
)).
params
(
map
).
get
(
url
);
return
response
;
}
//虚拟商品
public
Response
exchange3
(
String
appItemId
,
String
degreeId
,
Map
cookie
)
{
String
url
=
"http://"
+
seckillHost
+
"/appItemSecKill/exchange"
;
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"appItemId"
,
appItemId
);
map
.
put
(
"degreeId"
,
degreeId
);
Response
response
=
given
().
cookies
(
cookie
).
params
(
map
).
get
(
url
);
return
response
;
}
//话费
public
Response
exchange4
(
String
appItemId
,
String
itemId
,
int
uid
)
{
String
url
=
"http://"
+
seckillHost
+
"/appItemSecKill/exchange"
;
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"appItemId"
,
appItemId
);
map
.
put
(
"itemId"
,
itemId
);
map
.
put
(
"phone"
,
"13599944422"
);
map
.
put
(
"phoneCatName"
,
"中国移动"
);
map
.
put
(
"phoneProvince"
,
"福建"
);
Response
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
uid
)).
params
(
map
).
get
(
url
);
return
response
;
}
//话费
public
Response
exchange4
(
String
appItemId
,
String
itemId
,
Map
cookie
)
{
String
url
=
"http://"
+
seckillHost
+
"/appItemSecKill/exchange"
;
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"appItemId"
,
appItemId
);
map
.
put
(
"itemId"
,
itemId
);
map
.
put
(
"phone"
,
"13599944422"
);
map
.
put
(
"phoneCatName"
,
"中国移动"
);
map
.
put
(
"phoneProvince"
,
"福建"
);
Response
response
=
given
().
cookies
(
cookie
).
params
(
map
).
get
(
url
);
return
response
;
}
public
Response
queueQuery
(
String
queueId
,
Integer
uid
)
{
...
...
@@ -149,6 +249,27 @@ public class SeckillService {
return
response
;
}
public
Response
queueQuery
(
String
queueId
,
Map
cookie
)
{
String
url
=
"http://"
+
seckillHost
+
"/appItemSecKill/queueQuery"
;
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"queueId"
,
queueId
);
Response
response
=
given
().
cookies
(
cookie
).
params
(
map
).
get
(
url
);
return
response
;
}
public
Response
detail
(
String
orderId
,
Integer
uid
)
{
String
url
=
"http://"
+
seckillHost
+
"/taw/h5/detail"
;
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"orderId"
,
orderId
);
Response
response
=
given
().
cookies
(
authorization
.
dafuwengLogin
(
uid
)).
params
(
map
).
get
(
url
);
return
response
;
}
public
Response
getSeckillBtn
(
Long
duibaActivityId
,
Long
operationActivityId
,
Integer
uid
)
{
...
...
@@ -210,6 +331,10 @@ public class SeckillService {
}
public
static
void
main
(
String
args
[])
{
SeckillService
seckillService
=
new
SeckillService
();
...
...
src/test/java/http/service/app/gawService.java
View file @
ecaac2d5
...
...
@@ -76,4 +76,231 @@ public class gawService {
}
//实物sku兑换
public
Response
objectExchange
(
Map
cookies
,
String
appItemId
,
String
itemId
,
String
skuId
)
throws
Exception
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
mapList
=
new
HashMap
<>();
List
<
Map
>
list
=
new
ArrayList
<>();
mapList
.
put
(
"itemId"
,
itemId
);
mapList
.
put
(
"skuId"
,
skuId
);
mapList
.
put
(
"appItemId"
,
appItemId
);
mapList
.
put
(
"credits"
,
"100"
);
mapList
.
put
(
"price"
,
0
);
list
.
add
(
mapList
);
map
.
put
(
"remark"
,
""
);
//买家留言
map
.
put
(
"degreeId"
,
""
);
map
.
put
(
"actualPrice"
,
"0"
);
//总金额
map
.
put
(
"actualCredits"
,
"100"
);
//总积分
map
.
put
(
"itemParam"
,
list
.
toArray
());
map
.
put
(
"payType"
,
"3"
);
map
.
put
(
"expressPrice"
,
"0"
);
map
.
put
(
"validate"
,
""
);
map
.
put
(
"token"
,
"yrJRr7Cddp2YeQd"
);
JSONObject
jsonParam
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
map
));
logger
.
info
(
"请求实物兑换接口:"
+
"/gaw/objectExchange/create"
);
Response
response
=
given
().
contentType
(
"application/json; charset=UTF-8"
).
cookies
(
cookies
).
body
(
jsonParam
).
post
(
"http://"
+
goodsHost
+
"/gaw/objectExchange/create"
);
// Response saveResponse = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post("http://"+goodsHost+"/gaw/objectExchange/create");
// response.prettyPrint();
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"/gaw/objectExchange/create接口返回异常,返回信息:"
+
response
.
asString
());
}
catch
(
Error
er
){
throw
new
Exception
(
"/gaw/objectExchange/create接口返回异常,返回信息:"
+
response
.
asString
());
}
return
response
;
}
//优惠券兑换接口
public
Response
couponExchange
(
int
uid
,
String
appItemId
,
int
skuId
)
throws
Exception
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
mapList
=
new
HashMap
<>();
List
<
Map
>
list
=
new
ArrayList
<>();
mapList
.
put
(
"skuId"
,
skuId
);
mapList
.
put
(
"appItemId"
,
appItemId
);
mapList
.
put
(
"credits"
,
"100"
);
mapList
.
put
(
"price"
,
0
);
list
.
add
(
mapList
);
map
.
put
(
"remark"
,
""
);
//买家留言
map
.
put
(
"degreeId"
,
""
);
map
.
put
(
"actualPrice"
,
"0"
);
//总金额
map
.
put
(
"actualCredits"
,
"100"
);
//总积分
map
.
put
(
"itemParam"
,
list
.
toArray
());
map
.
put
(
"payType"
,
"3"
);
map
.
put
(
"expressPrice"
,
"0"
);
map
.
put
(
"validate"
,
""
);
map
.
put
(
"token"
,
"yrJRr7Cddp2YeQd"
);
JSONObject
jsonParam
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
map
));
logger
.
info
(
"请求实物兑换接口:"
+
"/gaw/couponExchange/create"
);
Response
response
=
given
().
contentType
(
"application/json; charset=UTF-8"
).
cookies
(
authorization
.
dafuwengLogin
(
uid
)).
body
(
jsonParam
).
post
(
"http://"
+
goodsHost
+
"/gaw/couponExchange/create"
);
// Response saveResponse = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post("http://"+goodsHost+"/gaw/objectExchange/create");
// response.prettyPrint();
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"/gaw/objectExchange/create接口返回异常,返回信息:"
+
response
.
asString
());
}
catch
(
Error
er
){
throw
new
Exception
(
"/gaw/objectExchange/create接口返回异常,返回信息:"
+
response
.
asString
());
}
return
response
;
}
//优惠券兑换
public
Response
couponExchange
(
Map
cookies
,
String
appItemId
,
String
itemId
,
String
skuId
)
throws
Exception
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
mapList
=
new
HashMap
<>();
List
<
Map
>
list
=
new
ArrayList
<>();
mapList
.
put
(
"itemId"
,
itemId
);
mapList
.
put
(
"skuId"
,
skuId
);
mapList
.
put
(
"appItemId"
,
appItemId
);
mapList
.
put
(
"credits"
,
"100"
);
mapList
.
put
(
"price"
,
0
);
list
.
add
(
mapList
);
map
.
put
(
"remark"
,
""
);
//买家留言
map
.
put
(
"actualPrice"
,
"0"
);
//总金额
map
.
put
(
"actualCredits"
,
"100"
);
//总积分
map
.
put
(
"itemParam"
,
list
.
toArray
());
map
.
put
(
"payType"
,
"3"
);
map
.
put
(
"validate"
,
""
);
map
.
put
(
"token"
,
"yrJRr7Cddp2YeQd"
);
JSONObject
jsonParam
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
map
));
logger
.
info
(
"请求实物兑换接口:"
+
"/gaw/couponExchange/create"
);
Response
response
=
given
().
contentType
(
"application/json; charset=UTF-8"
).
cookies
(
cookies
).
body
(
jsonParam
).
post
(
"http://"
+
goodsHost
+
"/gaw/couponExchange/create"
);
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"/gaw/couponExchange/create接口返回异常,返回信息:"
+
response
.
asString
());
}
catch
(
Error
er
){
throw
new
Exception
(
"/gaw/couponExchange/create接口返回异常,返回信息:"
+
response
.
asString
());
}
return
response
;
}
//优惠券兑换接口
public
Response
couponExchange
(
Map
cookie
,
String
appItemId
,
int
skuId
)
throws
Exception
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
mapList
=
new
HashMap
<>();
List
<
Map
>
list
=
new
ArrayList
<>();
mapList
.
put
(
"skuId"
,
skuId
);
mapList
.
put
(
"appItemId"
,
appItemId
);
mapList
.
put
(
"credits"
,
"100"
);
mapList
.
put
(
"price"
,
0
);
list
.
add
(
mapList
);
map
.
put
(
"remark"
,
""
);
//买家留言
map
.
put
(
"degreeId"
,
""
);
map
.
put
(
"actualPrice"
,
"0"
);
//总金额
map
.
put
(
"actualCredits"
,
"100"
);
//总积分
map
.
put
(
"itemParam"
,
list
.
toArray
());
map
.
put
(
"payType"
,
"3"
);
map
.
put
(
"expressPrice"
,
"0"
);
map
.
put
(
"validate"
,
""
);
map
.
put
(
"token"
,
"yrJRr7Cddp2YeQd"
);
JSONObject
jsonParam
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
map
));
logger
.
info
(
"请求实物兑换接口:"
+
"/gaw/couponExchange/create"
);
Response
response
=
given
().
contentType
(
"application/json; charset=UTF-8"
).
cookies
(
cookie
).
body
(
jsonParam
).
post
(
"http://"
+
goodsHost
+
"/gaw/couponExchange/create"
);
// Response saveResponse = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post("http://"+goodsHost+"/gaw/objectExchange/create");
// response.prettyPrint();
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"/gaw/objectExchange/create接口返回异常,返回信息:"
+
response
.
asString
());
}
catch
(
Error
er
){
throw
new
Exception
(
"/gaw/objectExchange/create接口返回异常,返回信息:"
+
response
.
asString
());
}
return
response
;
}
//虚拟商品兑换接口
public
Response
virtualExchange
(
Map
cookie
,
String
appItemId
,
int
skuId
)
throws
Exception
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Map
<
String
,
Object
>
mapList
=
new
HashMap
<>();
List
<
Map
>
list
=
new
ArrayList
<>();
mapList
.
put
(
"skuId"
,
skuId
);
mapList
.
put
(
"appItemId"
,
appItemId
);
mapList
.
put
(
"credits"
,
"100"
);
mapList
.
put
(
"price"
,
0
);
list
.
add
(
mapList
);
map
.
put
(
"remark"
,
""
);
//买家留言
map
.
put
(
"degreeId"
,
""
);
map
.
put
(
"actualPrice"
,
"0"
);
//总金额
map
.
put
(
"actualCredits"
,
"100"
);
//总积分
map
.
put
(
"itemParam"
,
list
.
toArray
());
map
.
put
(
"payType"
,
"3"
);
map
.
put
(
"expressPrice"
,
"0"
);
map
.
put
(
"validate"
,
""
);
map
.
put
(
"token"
,
"yrJRr7Cddp2YeQd"
);
JSONObject
jsonParam
=
JSONObject
.
parseObject
(
JSON
.
toJSONString
(
map
));
logger
.
info
(
"请求实物兑换接口:"
+
"/gaw/couponExchange/create"
);
Response
response
=
given
().
contentType
(
"application/json; charset=UTF-8"
).
cookies
(
cookie
).
body
(
jsonParam
).
post
(
"http://"
+
goodsHost
+
"/gaw/virtualExchange/create"
);
// Response saveResponse = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.dafuwengLogin(uid)).params(map).post("http://"+goodsHost+"/gaw/objectExchange/create");
// response.prettyPrint();
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"success"
),
"true"
);
}
catch
(
Exception
e
){
throw
new
Exception
(
"/gaw/objectExchange/create接口返回异常,返回信息:"
+
response
.
asString
());
}
catch
(
Error
er
){
throw
new
Exception
(
"/gaw/objectExchange/create接口返回异常,返回信息:"
+
response
.
asString
());
}
return
response
;
}
}
src/test/java/http/service/hd/DsOrderService.java
View file @
ecaac2d5
...
...
@@ -41,6 +41,7 @@ public class DsOrderService {
logger
.
info
(
"请求订单审核接口:"
+
url
);
Response
response
=
given
().
contentType
(
"application/x-www-form-urlencoded;charset=UTF-8"
).
cookies
(
authorization
.
hdLogin
()).
params
(
map
).
post
(
"http://"
+
url
);
logger
.
info
(
"请求订单审核接口结束"
);
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"desc"
),
"成功"
);
}
catch
(
Exception
e
){
...
...
@@ -63,6 +64,7 @@ public class DsOrderService {
logger
.
info
(
"请求订单审核接口:"
+
url
);
Response
response
=
given
().
contentType
(
"application/x-www-form-urlencoded;charset=UTF-8"
).
cookies
(
authorization
.
hdLoginCommon
(
email
)).
params
(
map
).
post
(
"http://"
+
url
);
logger
.
info
(
"请求订单审核接口结束"
);
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"desc"
),
"成功"
);
}
catch
(
Exception
e
){
...
...
@@ -85,6 +87,7 @@ public class DsOrderService {
logger
.
info
(
"请求订单审核接口:"
+
url
);
Response
response
=
given
().
contentType
(
"application/x-www-form-urlencoded;charset=UTF-8"
).
cookies
(
cookies
).
params
(
map
).
post
(
"http://"
+
url
);
logger
.
info
(
"请求订单审核接口结束"
);
try
{
Assert
.
assertEquals
(
response
.
jsonPath
().
getString
(
"desc"
),
"成功"
);
}
catch
(
Exception
e
){
...
...
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