Commit e759bed8 authored by 胡梦新's avatar 胡梦新

hmx

parent 81f452ba
package http.cases.SaasDeveloperTest;
import base.Config;
import http.service.Saas.DeveloperBJZ;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.Assert;
import org.testng.annotations.Test;
@ContextConfiguration(classes = Config.class)
public class 补给站_活动 extends AbstractTestNGSpringContextTests{
@Autowired
DeveloperBJZ developerBJZ;
private DuibaLog logger = DuibaLog.getLogger();
//至尊版app
String appId="19515";
//旗舰版app
String appId2="21695";
//添加活动
@Test(description = "//添加活动")
public void a_添加活动() throws Exception{
//查询热门活动-活动列表,获取商品ID
Response response=developerBJZ.saasActivitys("3",appId);
String goodItemId= String.valueOf(response.jsonPath().getString("data.saasActivitys[0].id"));
//获取商品ID,进入商品订购页面,获取SKU
Response response2=developerBJZ.itemOrderDetail(goodItemId,appId);
String skuId= String.valueOf(response2.jsonPath().getString("data.goodsItemSku[0].skuId"));
//点击订购,传入SKU创建订单
logger.info("kuid==="+skuId);
Response response3=developerBJZ.createAutomationOrderNew(skuId,appId);
String orderid= String.valueOf(response3.jsonPath().getString("data"));
logger.info("kuid==="+orderid);
//下单购买
developerBJZ.orderAccountPay(orderid,appId);
//查询是否购买成功
Response response4=developerBJZ.findOrderById(orderid,appId);
Assert.assertEquals(response4.jsonPath().getString("data.vo.funcName"), "自动化测试活动--勿动", "校验名称失败");
Assert.assertEquals(response4.jsonPath().getString("data.vo.limitTime"), "一年", "校验购买期限失败");
logger.info("校验名称,期限成功");
}
@Test(description = "//添加签到活动")
public void b_添加签到活动() throws Exception{
//查询热门活动-活动列表,获取商品ID
Response response=developerBJZ.saasActivitys("2",appId);
String goodItemId= String.valueOf(response.jsonPath().getString("data.saasActivitys[1].id"));
//获取商品ID,进入商品订购页面,获取SKU
Response response2=developerBJZ.itemOrderDetail(goodItemId,appId);
String skuId= String.valueOf(response2.jsonPath().getString("data.goodsItemSku[0].skuId"));
//点击订购,传入SKU创建订单
logger.info("kuid==="+skuId);
Response response3=developerBJZ.createAutomationOrderNew(skuId,appId);
String orderid= String.valueOf(response3.jsonPath().getString("data"));
logger.info("kuid==="+orderid);
//下单购买
developerBJZ.orderAccountPay(orderid,appId);
//查询是否购买成功
Response response4=developerBJZ.findOrderById(orderid,appId);
Assert.assertEquals(response4.jsonPath().getString("data.vo.funcName"), "SaaS签到", "校验名称失败");
logger.info("校验名称成功");
}
@Test(description = "付款时有待处理的订单(异常场景)")
public void c_待处理的订单() throws Exception{
//查询热门活动-活动列表,获取商品ID
Response response=developerBJZ.saasActivitys("2",appId);
String goodItemId= String.valueOf(response.jsonPath().getString("data.saasActivitys[1].id"));
//获取商品ID,进入商品订购页面,获取SKU
Response response2=developerBJZ.itemOrderDetail(goodItemId,appId);
String skuId= String.valueOf(response2.jsonPath().getString("data.goodsItemSku[0].skuId"));
//点击订购,传入SKU创建订单
logger.info("kuid==="+skuId);
developerBJZ.createAutomationOrderNew(skuId,appId);
developerBJZ.createAutomationOrderNew2(skuId,appId);
Assert.assertEquals(developerBJZ.createAutomationOrderNew2(skuId,appId).jsonPath().getString("desc"), "订单未处理", "校验订单待处理成功");
//查询待处理订单
Response response3=developerBJZ.selectOrders("1",appId);
Assert.assertEquals(response3.jsonPath().getString("data.list[0].serviceName"), "SaaS签到", "校验名称失败");
logger.info("查询待处理订单成功");
}
@Test(description="查询交易关闭的订单")
public void d_交易关闭的订单() throws Exception{
//查询待付款订单
Response response=developerBJZ.selectOrders("1",appId);
String orderId=String.valueOf(response.jsonPath().getString("data.list[0].id"));
// 点击取消付款,进入到交易关闭订单
developerBJZ.cancleOrder(orderId,appId);
Response response2=developerBJZ.selectOrders("3",appId);
Assert.assertEquals(response2.jsonPath().getString("data.list[0].serviceName"), "SaaS签到", "校验名称失败");
logger.info("查询交易关闭订单成功");
}
}
......@@ -249,7 +249,7 @@ public class Authorization {
public Map hdLoginSaas(String appId){
int i=10;
//logger.info("hdCookiesSaasByApp cookies:"+hdCookiesSaasByApp.toString());
logger.info("hdCookiesSaasByApp cookies:"+hdCookiesSaasByApp.toString());
Map<String,String> hdCookies = hdCookiesSaasByApp.get(appId);
while((hdCookies==null||hdCookies.size()==0)&&i>0) {
Response token=this.hdGetToken();
......@@ -261,15 +261,15 @@ public class Authorization {
paras.put("redirect", "/redirectApp");
paras.put("isAutoLogin", "true");
Response response = given().cookies(cookies).params(paras).post(url);
// Map<String,String> map = response.getCookies();
// logger.info("cookies:"+map.toString());
Map<String,String> map = response.getCookies();
logger.info("cookies:"+map.toString());
hdCookies=new HashMap<>(response.getCookies());
if(hdCookies!=null||hdCookies.size()!=0) {
//取消安全校验
hdCookies.remove("csrf_token");
hdCookies.put("appId", appId);
hdCookies.put("duibaAppId", appId);
//logger.info("cookies2:"+hdCookies.toString());
logger.info("cookies2:"+hdCookies.toString());
hdCookiesSaasByApp.put(appId,hdCookies);
}
......
......@@ -220,6 +220,21 @@ public class DeveloperBJZ {
return response;
}
//订购活动--创建订单
public Response createAutomationOrderNew2(String skuId, String appId) throws Exception {
String url = "http://" + hdHost + "/saas/createAutomationOrderNew";
Map<String, String> map = new HashMap<>();
map.put("skuId", skuId);
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.hdLoginSaas(appId)).params(map).post(url);
try {
Assert.assertEquals(response.jsonPath().getString("desc"), "订单未处理");
} catch (Exception e) {
throw new Exception("创建接口1失败,返回信息:" + response.asString());
} catch (Error er) {
throw new Exception("创建接口2失败,返回信息:" + response.asString());
}
return response;
}
//订购--账户余额付款
public Response orderAccountPay(String orderId, String appId) throws Exception {
String url = "http://" + hdHost + "/saas/orderAccountPay";
......@@ -254,10 +269,10 @@ public class DeveloperBJZ {
}
//查看记录是否添加购买成功
public Response selectOrders(String appId) throws Exception {
public Response selectOrders(String orderStatus, String appId) throws Exception {
String url = "http://" + hdHost + "/saas/selectOrders";
Map<String, String> map = new HashMap<>();
map.put("orderStatus","2");
map.put("orderStatus",orderStatus);
map.put("appId",appId);
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.hdLoginSaas(appId)).params(map).get(url);response.prettyPrint();
try {
......@@ -270,6 +285,23 @@ public class DeveloperBJZ {
return response;
}
//取消付款
public Response cancleOrder(String orderId ,String appId) throws Exception {
String url = "http://" + hdHost + "/saas/cancleOrder";
Map<String, String> map = new HashMap<>();
map.put("orderId",orderId);
Response response = given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.hdLoginSaas(appId)).params(map).post(url);
response.prettyPrint();
try {
Assert.assertEquals(response.jsonPath().getString("desc"), "成功");
} catch (Exception e) {
throw new Exception("创建接口1失败,返回信息:" + response.asString());
} catch (Error er) {
throw new Exception("创建接口2失败,返回信息:" + response.asString());
}
return response;
}
//查询直冲类商品
public Response directCharges(String appId) throws Exception {
String url = "http://" + hdHost + "/saasitem/directCharges";
......
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