Commit 8830a136 authored by chenjianfang's avatar chenjianfang

hmx

parent db0c8570
package http.cases.SaasDeveloperTest;
import base.Config;
import utils.PublicMethod;
import http.service.Saas.DeveloperVirtualService;
import http.service.Saas.SpglczService;
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;
/**
* Created by humengxin on 2018/11/02.
*/
@ContextConfiguration(classes = Config.class)
public class 商品管理操作_DuibaTest extends AbstractTestNGSpringContextTests {
@Autowired
SpglczService czService;
@Autowired
DeveloperVirtualService developerVirtualService;
private static DuibaLog logger = DuibaLog.getLogger();
@Test(description = "批量上架")
public void a_批量上架() throws Exception {
String data=PublicMethod.data();
//先添加2个商品
developerVirtualService.doUpdateVirtual("【自动化】加钱购自有虚拟商品"+data,"标识符100=10+1");
developerVirtualService.doUpdateVirtual("【自动化】加钱购自有虚拟商品"+data,"标识符100=10+1");
//查询实物商品集合
Response response= czService.appItems();
// 获取到上架商品id
String ids = response.jsonPath().getString("data.list[0].id");
String ids2 = response.jsonPath().getString("data.list[1].id");
czService.batchStandUpOrDown(ids,ids2);
//刷新查询商品集合
Response response2= czService.appItems();
//查看商品列表确认是否上架成功
Assert.assertEquals(response2.jsonPath().getString("data.list[0].statusText"),"上架", "校验商品上架失败");
Assert.assertEquals(response2.jsonPath().getString("data.list[1].statusText"),"上架", "校验商品上架失败");
logger.info("校验商品上架成功");
}
@Test(description = "批量复制")
public void b_批量复制() throws Exception {
String data = PublicMethod.data();
//查询实物商品集合
Response response= czService.appItems();
// 获取到上架商品id
String ids = response.jsonPath().getString("data.list[0].id");
String ids2 = response.jsonPath().getString("data.list[1].id");
//复制到另一个app
czService.batchCopy(ids,ids2);
//查看另一个app下是否存在该商品
Response response2=czService.appItems2();
Assert.assertEquals(response2.jsonPath().getString("data.list[0].itemType"), "直充", "校验商品类型失败");
Assert.assertEquals(response2.jsonPath().getString("data.list[0].belong"), "自有", "校验商品belong失败");
Assert.assertEquals(response2.jsonPath().getString("data.list[1].itemType"), "直充", "校验商品类型失败");
Assert.assertEquals(response2.jsonPath().getString("data.list[1].belong"), "自有", "校验商品belong失败");
logger.info("校验title,belong成功");
}
@Test(description = "批量删除")
public void c_批量删除() throws Exception {
String data = PublicMethod.data();
//查询实物商品集合
Response response= czService.appItems();
// 获取到上架商品id
String ids = response.jsonPath().getString("data.list[0].id");
String ids2 = response.jsonPath().getString("data.list[1].id");
czService.doBatchDel(ids,ids2);
}
}
package http.service.Saas;
import http.service.Authorization;
import base.DuibaLog;
import io.restassured.response.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.testng.Assert;
import java.util.HashMap;
import java.util.Map;
import static io.restassured.RestAssured.given;
/**
* Created by asus on 2018/11/2.
*/
@Service
public class SpglczService {
@Value("${hdserver.host}")
String hdHost;
@Autowired
Authorization authorization;
private DuibaLog logger = DuibaLog.getLogger();
//查询商品管理列表数据
public Response appItems() throws Exception {
String url=hdHost+"/devItem/appItems";
Map<String,String> map = new HashMap<>();
map.put("appId","19515");
map.put("rowId","1");
map.put("itemType","");
map.put("status","");
map.put("itemName","");
map.put("belong","");
map.put("priceType","");
logger.info("请求查询商品url:"+url);
Response response=given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.hdLoginSaas()).params(map).post("http://"+url);
response.prettyPrint();
try{
Assert.assertEquals(response.jsonPath().getString("desc"),"成功");
}catch(Exception e){
throw new Exception("查询商品管理列表数据接口失败,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("查询商品管理列表数据接口失败,返回信息:"+response.asString());
}
return response;
}
//查询要复制的app数据
public Response appItems2() throws Exception {
String url=hdHost+"/devItem/appItems";
Map<String,String> map = new HashMap<>();
map.put("appId","20979");
map.put("rowId","1");
map.put("itemType","");
map.put("status","");
map.put("itemName","");
map.put("belong","");
map.put("priceType","");
logger.info("请求查询商品url:"+url);
Response response=given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.hdLoginSaas()).params(map).post("http://"+url);
response.prettyPrint();
try{
Assert.assertEquals(response.jsonPath().getString("desc"),"成功");
}catch(Exception e){
throw new Exception("查询商品管理列表数据接口失败,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("查询商品管理列表数据接口失败,返回信息:"+response.asString());
}
return response;
}
// 批量上架
public Response batchStandUpOrDown(String ids,String ids2) throws Exception {
String url=hdHost+"/devItem/batchStandUpOrDown";
Map<String,String> map = new HashMap<>();
map.put("appId","19515");
map.put("ids",ids+","+ids2);
logger.info("请求批量上架商品url:"+url);
Response response=given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.hdLoginSaas()).params(map).post("http://"+url);
response.prettyPrint();
try{
Assert.assertEquals(response.jsonPath().getString("desc"),"成功");
}catch(Exception e){
throw new Exception("批量上架接口失败,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("批量上架接口失败,返回信息:"+response.asString());
}
return response;
}
//批量复制
public Response batchCopy(String ids,String ids2) throws Exception {
String url=hdHost+"/devItem/batchCopy";
Map<String,String> map=new HashMap<>();
map.put("appId","19515");
map.put("ids",ids+","+ids2);
map.put("toAppIds","20979");
logger.info("请求批量商品url:"+url);
Response response=given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.hdLoginSaas()).params(map).post("http://"+url);
try{
Assert.assertEquals(response.jsonPath().getString("success"), "true");
}catch(Exception e){
throw new Exception("批量复制 接口失败,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("批量复制 接口失败,返回信息:"+response.asString());
}
return response;
}
//批量删除
public Response doBatchDel(String ids,String ids2 ) throws Exception {
String url=hdHost+"/devItem/doBatchDel";
Map<String,String> map=new HashMap<>();
map.put("appId","19515");
map.put("ids", ids+","+ids2);
logger.info("请求批量商品url:"+url);
Response response=given().contentType("application/x-www-form-urlencoded;charset=UTF-8").cookies(authorization.hdLoginSaas()).params(map).post("http://"+url);
try{
Assert.assertEquals(response.jsonPath().getString("success"), "true");
}catch(Exception e){
throw new Exception("批量删除 接口失败,返回信息:"+response.asString());
}catch(Error er){
throw new Exception("批量删除 接口失败,返回信息:"+response.asString());
}
return response;
}
}
\ No newline at end of file
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