Commit ecaac2d5 authored by 赵然's avatar 赵然

Merge branch 'master' of gitlab2.dui88.com:mabo/test-platform

parents 399aed5e a5827141
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
<dependency> <dependency>
<groupId>io.rest-assured</groupId> <groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId> <artifactId>rest-assured</artifactId>
<version>3.0.3</version> <version>3.3.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
......
...@@ -7,6 +7,7 @@ import org.springframework.context.ApplicationContext; ...@@ -7,6 +7,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.*; import java.util.*;
...@@ -62,8 +63,14 @@ public class DingdingResult { ...@@ -62,8 +63,14 @@ public class DingdingResult {
changes = Postman.sendFindTestApp(params); changes = Postman.sendFindTestApp(params);
} }
gitlabProjectMerges = GitlabUtils.getMessage("credits-group",changes); try{
changes = changes+" 提交者:"+gitlabProjectMerges.getAuthor().getName()+" 描述:"+gitlabProjectMerges.getDescription(); gitlabProjectMerges = GitlabUtils.getMessage("credits-group",changes);
changes = changes+" 提交者:"+gitlabProjectMerges.getAuthor().getName()+" 描述:"+gitlabProjectMerges.getDescription();
}catch (Exception e){
logger.info("不是兑吧服务,未发现变革");
}
this.total=total; this.total=total;
...@@ -125,6 +132,7 @@ public class DingdingResult { ...@@ -125,6 +132,7 @@ public class DingdingResult {
// System.out.println(e); // System.out.println(e);
// } // }
if(gitlabProjectMerges!=null)
names.add(gitlabProjectMerges.getAuthor().getUsername()); names.add(gitlabProjectMerges.getAuthor().getUsername());
}else { }else {
......
package base; 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.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
...@@ -8,6 +11,9 @@ import org.testng.annotations.BeforeSuite; ...@@ -8,6 +11,9 @@ import org.testng.annotations.BeforeSuite;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import static io.restassured.RestAssured.config;
import static io.restassured.config.HttpClientConfig.httpClientConfig;
/** /**
* Created by mabo on 2018/9/20 * Created by mabo on 2018/9/20
*/ */
...@@ -25,6 +31,11 @@ public class DuibaBase extends AbstractTestNGSpringContextTestsDuiba { ...@@ -25,6 +31,11 @@ public class DuibaBase extends AbstractTestNGSpringContextTestsDuiba {
logger.info("--------------------DuibaBase.setUp() Tests"); logger.info("--------------------DuibaBase.setUp() Tests");
//只初始化一次 //只初始化一次
jdbc.initDataSource(); 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
} }
......
...@@ -14,15 +14,13 @@ import java.util.List; ...@@ -14,15 +14,13 @@ import java.util.List;
public class GitlabUtils { public class GitlabUtils {
public static final String GIT_URL = "http://gitlab2.dui88.com"; public static final String GIT_URL = "http://gitlab2.dui88.com";
public static final String SECRET = "rCyBy1sQ-JckquyFmo4c"; 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); GitlabAPI gitlabAPI = GitlabAPI.connect(GitlabUtils.GIT_URL, GitlabUtils.SECRET);
GitlabProject gitlabProject= null; GitlabProject gitlabProject= null;
try {
gitlabProject = gitlabAPI.getProject(namespace,projectname); gitlabProject = gitlabAPI.getProject(namespace,projectname);
// gitlabProject = gitlabAPI.getProject("credits-group","hdtool-web"); // gitlabProject = gitlabAPI.getProject("credits-group","hdtool-web");
} catch (IOException e) {
e.printStackTrace();
}
GitabProjectLatelyChangeQry qry = new GitabProjectLatelyChangeQry(); GitabProjectLatelyChangeQry qry = new GitabProjectLatelyChangeQry();
qry.setId(gitlabProject.getId()); qry.setId(gitlabProject.getId());
......
...@@ -18,10 +18,16 @@ public class CheckTemplet extends DuibaBase { ...@@ -18,10 +18,16 @@ public class CheckTemplet extends DuibaBase {
@BeforeSuite @BeforeSuite
public void setTemplet() throws Exception { public void setTemplet() throws Exception {
logger.info("------------------------setTemplet()"); try{
this.setVirtual(); logger.info("------------------------setTemplet()");
Thread.sleep(1000); this.setVirtual();
this.setQb(); Thread.sleep(1000);
this.setQb();
}catch (Exception e){
e.printStackTrace();
}
} }
public void setVirtual() throws Exception { public void setVirtual() throws Exception {
......
...@@ -14,4 +14,8 @@ public class Database { ...@@ -14,4 +14,8 @@ public class Database {
public static String orders7 = "orders_0211"; public static String orders7 = "orders_0211";
public static String orders8 = "orders_0090"; public static String orders8 = "orders_0090";
public static String orders9 = "orders_0203"; public static String orders9 = "orders_0203";
public static String orders10 = "orders_0411";
public static String orders11 = "orders_0182";
} }
...@@ -696,59 +696,6 @@ public class 兑吧老优惠券_兑换流程测试_ExchangeTest extends CheckTem ...@@ -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 = "兑吧优惠券会员等级测试") @Test(description = "兑吧优惠券会员等级测试")
public void 会员等级测试()throws Exception{ public void 会员等级测试()throws Exception{
......
...@@ -146,7 +146,7 @@ public class 多档位话费_兑换流程测试_ExchangeTest extends CheckTemple ...@@ -146,7 +146,7 @@ public class 多档位话费_兑换流程测试_ExchangeTest extends CheckTemple
message = e.toString(); message = e.toString();
} }
logger.info(message); logger.info("message: " + message);
//获取按钮状态 //获取按钮状态
Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"1"); Response detailResponse = mobileService.detail(authorization.dafuwengLogin(uid),"1");
......
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");
}
}
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();
}
}
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,"等待商家发货");
}
}
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");
}
}
...@@ -197,6 +197,15 @@ public class Authorization { ...@@ -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(){ public Map hdLogin(){
......
...@@ -249,6 +249,37 @@ public class CouponExchangeService { ...@@ -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 { public Response objectExchange(String appItemId,String itemId) throws Exception {
Map<String,String> map = new HashMap<>(); Map<String,String> map = new HashMap<>();
map.put("appItemId",appItemId); map.put("appItemId",appItemId);
......
...@@ -41,6 +41,7 @@ public class DsOrderService { ...@@ -41,6 +41,7 @@ public class DsOrderService {
logger.info("请求订单审核接口:" + url); logger.info("请求订单审核接口:" + url);
Response response=given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.hdLogin()).params(map).post("http://"+url); Response response=given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.hdLogin()).params(map).post("http://"+url);
logger.info("请求订单审核接口结束");
try{ try{
Assert.assertEquals(response.jsonPath().getString("desc"),"成功"); Assert.assertEquals(response.jsonPath().getString("desc"),"成功");
}catch(Exception e){ }catch(Exception e){
...@@ -63,6 +64,7 @@ public class DsOrderService { ...@@ -63,6 +64,7 @@ public class DsOrderService {
logger.info("请求订单审核接口:" + url); logger.info("请求订单审核接口:" + url);
Response response=given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.hdLoginCommon(email)).params(map).post("http://"+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{ try{
Assert.assertEquals(response.jsonPath().getString("desc"),"成功"); Assert.assertEquals(response.jsonPath().getString("desc"),"成功");
}catch(Exception e){ }catch(Exception e){
...@@ -85,6 +87,7 @@ public class DsOrderService { ...@@ -85,6 +87,7 @@ public class DsOrderService {
logger.info("请求订单审核接口:" + url); logger.info("请求订单审核接口:" + url);
Response response=given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(cookies).params(map).post("http://"+url); Response response=given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(cookies).params(map).post("http://"+url);
logger.info("请求订单审核接口结束");
try{ try{
Assert.assertEquals(response.jsonPath().getString("desc"),"成功"); Assert.assertEquals(response.jsonPath().getString("desc"),"成功");
}catch(Exception e){ }catch(Exception e){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment