m-接口自动化-快速入门

在这里插入图片描述

package com.sankuai.sjst.qa.coreservice.api.test.thrift.cos.customer;

import com.alibaba.fastjson.JSONObject;


import com.sankuai.meituan.zcm.component.customer.thrift.model.*;
import com.sankuai.meituan.zcm.component.customer.thrift.model.TBoolResult;
import com.sankuai.meituan.zcm.component.customer.thrift.service.ExcelThriftService;
import com.sankuai.sjst.qa.coreservice.api.lib.dao.cos.customer.mapper.customerMapper;
import com.sankuai.sjst.qa.testbase.common.annotations.Contributor;
import com.sankuai.sjst.qa.testbase.common.testbase.TestBase;
import com.sankuai.sjst.qa.testbase.util.AssertUtil;
import com.sankuai.sjst.qa.testbase.util.SpringContextsUtil;
import com.sankuai.zcm.customer.thrift.common.*;
import com.sankuai.zcm.customer.thrift.common.TCustomerQueryReq;
import com.sankuai.zcm.customer.thrift.common.TLongResult;
import com.sankuai.zcm.customer.thrift.common.TPage;
import com.sankuai.zcm.customer.thrift.hq.THqNoAndBizLineDTO;
import com.sankuai.zcm.customer.thrift.service.*;
import org.apache.thrift.TException;
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;
import javax.annotation.Resource;
import java.io.*;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

@ContextConfiguration(locations = {"classpath:thrift-context/com.sankuai.zc.cos.customer/zcm-customer.xml","classpath:mybatis-context/com.sankuai.zc.cos.customer/cos-customer.xml"})
public class CustomerThriftServiceTest extends TestBase {
    @Resource
    CustomerThriftService.Iface customerThriftService;

    @Resource
    ExcelThriftService.Iface excelThriftService;

    @Resource //注入这个类
    TCustomerUnitService.Iface tCustomerUnitService;


    private Integer customerId = null;

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "客户列表-新增客户",dataProvider = "json-ext") //case名称,传参的类型json
    public void addCustomer(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TCustomerEditReq customerUnit = request.parseObject(request.getString("customerUnit"), TCustomerEditReq.class);
        String name = customerUnit.getEditDTO().getBase().getName();
        int type = customerUnit.getEditDTO().getBase().getType();
        TLongResult tLongResult = customerThriftService.addCustomer(customerUnit);
        customerMapper customerMapper = (customerMapper) SpringContextsUtil.getBean("customerMapper");
        Integer DBcustomerID = customerMapper.getCustomerID(name, type);
        customerId = DBcustomerID;
        if (customerId!=null){
            String filePath = "src/test/resources-test/config.properties";
            String newKey = "customerId";
            String newValue = customerId.toString();
            boolean isKeyExist = false;
            File configFile = new File(filePath);
            List<String> configLines = new ArrayList<>();
            // 读取原配置文件内容到内存中
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    // 判断新配置是否已存在
                    if (line.startsWith(newKey + "=")) {
                        isKeyExist = true;
                    }
                    configLines.add(line);
                }
            } catch (IOException io) {
                io.printStackTrace();
            }
            // 如果新配置不存在,则在内存中添加新配置
            if (!isKeyExist) {
                configLines.add(newKey + "=" + newValue);
            }

            // 将修改后的内容覆盖写回原配置文件
            try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8))) {
                for (String line : configLines) {
                    writer.write(line);
                    writer.newLine();
                }
            } catch (IOException io) {
                io.printStackTrace();
            }
            AssertUtil.assertTrue(customerId!=null);
        }
        else {
            logger.info(tLongResult);
            AssertUtil.assertFalse(customerId==null);
        }
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "客户编辑-冲突规则分析",dataProvider = "json-ext") //case名称,传参的类型json
    public void analyzeRules(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TCustomerRuleAnalyzeReq rules = request.parseObject(request.getString("rules"), TCustomerRuleAnalyzeReq.class);
        TCustomerRuleAnalysisResult tCustomerRuleAnalysisResult = customerThriftService.analyzeRules(rules);
        logger.info(tCustomerRuleAnalysisResult);
        AssertUtil.assertByCompareJSONLenient(tCustomerRuleAnalysisResult,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "客户编辑-「新增+修改」基础信息回显",dataProvider = "json-ext") //case名称,传参的类型json
    public void getCustomerInfo(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TCustomerInfoQueryReq req = request.parseObject(request.getString("req"), TCustomerInfoQueryReq.class);
        TCustomerInfoResult customerInfo = customerThriftService.getCustomerInfo(req);
        logger.info(customerInfo);
        AssertUtil.assertByCompareJSONLenient(customerInfo,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "客户列表-获取客户筛选字段枚举值",dataProvider = "json-ext") //case名称,传参的类型json
    public void getCustomerEnums(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        int operatorId = Integer.parseInt(request.getString("operatorId"));
        TCustomerFeatureEnumRes customerEnums = customerThriftService.getCustomerEnums(operatorId);
        logger.info(customerEnums);
        AssertUtil.assertByCompareJSONLenient(customerEnums,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "客户列表-分页查询客户信息",dataProvider = "json-ext") //case名称,传参的类型json
    public void queryCustomerByPage(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TCustomerQueryReq req = request.parseObject(request.getString("req"), TCustomerQueryReq.class);
        TPage page = request.parseObject(request.getString("page"), TPage.class);
        TCustomerPageResult tCustomerPageResult = customerThriftService.queryCustomerByPage(req, page);
        logger.info(tCustomerPageResult);
        AssertUtil.assertByCompareJSONLenient(tCustomerPageResult,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "客户列表-分页查询客户信息",dataProvider = "json-ext") //case名称,传参的类型json
    public void getCustomerTitleDisplay(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        int operatorId = Integer.parseInt(request.getString("operatorId"));
        GetCustomerTitleDisplayResp customerTitleDisplay = customerThriftService.getCustomerTitleDisplay(operatorId);
        logger.info(customerTitleDisplay);
        AssertUtil.assertByCompareJSONLenient(customerTitleDisplay,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "客户列表-查询客户信息",dataProvider = "json-ext") //case名称,传参的类型json
    public void getCustomerBasicInfo(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TCustomerInfoQueryReq req = request.parseObject(request.getString("req"), TCustomerInfoQueryReq.class);
        TCustomerBasicInfoResult customerBasicInfo = null;
        try {
            customerBasicInfo = customerThriftService.getCustomerBasicInfo(req);
            logger.info(customerBasicInfo);
            AssertUtil.assertByCompareJSONLenient(customerBasicInfo,expect);
        } catch (TException e) {
            logger.error("接口返回值中Required field 'url'= null (这是一个遗留问题,请重点关注)");
        }
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "客户列表-客户详细信息查看",dataProvider = "json-ext") //case名称,传参的类型json
    public void getCustomerDetailInfo(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TCustomerInfoQueryReq req = request.parseObject(request.getString("req"), TCustomerInfoQueryReq.class);
        TCustomerDetailInfoResult customerDetailInfo = customerThriftService.getCustomerDetailInfo(req);
        logger.info(customerDetailInfo);
        AssertUtil.assertByCompareJSONLenient(customerDetailInfo,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "客户列表-修改客户",dataProvider = "json-ext") //case名称,传参的类型json
    public void updateCustomer(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TCustomerEditReq customerUnit = request.parseObject(request.getString("customerUnit"), TCustomerEditReq.class);
        TLongResult tLongResult = customerThriftService.updateCustomer(customerUnit);
        logger.info(tLongResult);
        AssertUtil.assertByCompareJSONLenient(tLongResult,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "按品牌-批量新增客户",dataProvider = "json-ext") //case名称,传参的类型json
    public void batchAddCustomer(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TCustomerBatchAddReq tCustomerBatchAddReq = request.parseObject(request.getString("TCustomerBatchAddReq"), TCustomerBatchAddReq.class);
        TCustomerBatchAddResult tCustomerBatchAddResult = customerThriftService.batchAddCustomer(tCustomerBatchAddReq);
        logger.info(tCustomerBatchAddResult);
        AssertUtil.assertByCompareJSONLenient(tCustomerBatchAddResult,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "批量编辑客户",dataProvider = "json-ext") //case名称,传参的类型json
    public void batchEditCustomer(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TBatchEditCustomerReq tBatchEditCustomerReq = request.parseObject(request.getString("TBatchEditCustomerReq"), TBatchEditCustomerReq.class);
        TCustomerBatchEditResult tCustomerBatchEditResult = customerThriftService.batchEditCustomer(tBatchEditCustomerReq);
        logger.info(tCustomerBatchEditResult);
        AssertUtil.assertByCompareJSONLenient(tCustomerBatchEditResult,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "查询客户视图信息",dataProvider = "json-ext") //case名称,传参的类型json
    public void getCustomerMetricsView(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TCustomerInfoQueryReq req = request.parseObject(request.getString("req"), TCustomerInfoQueryReq.class);
        TCustomerMetricsViewResult customerMetricsView = customerThriftService.getCustomerMetricsView(req);
        logger.info(customerMetricsView);
        AssertUtil.assertByCompareJSONLenient(customerMetricsView,expect);
    }


    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "查询customer_poi门店信息",dataProvider = "json-ext") //case名称,传参的类型json
    public void searchCustomerPois(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        int lastId = Integer.parseInt(request.getString("lastId"));
        int size = Integer.parseInt(request.getString("size"));
        TCustomerPoiInfoResult tCustomerPoiInfoResult = customerThriftService.searchCustomerPois(lastId, size);
        logger.info(tCustomerPoiInfoResult);
        AssertUtil.assertByCompareJSONLenient(tCustomerPoiInfoResult,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "查询客户范围信息",dataProvider = "json-ext") //case名称,传参的类型json
    public void getCustomerScopeInfo(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TCustomerInfoQueryReq req = request.parseObject(request.getString("req"), TCustomerInfoQueryReq.class);
        TCustomerScopeInfoResult customerScopeInfo = customerThriftService.getCustomerScopeInfo(req);
        logger.info(customerScopeInfo);
        AssertUtil.assertByCompareJSONLenient(customerScopeInfo,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "查询客户组织信息",dataProvider = "json-ext") //case名称,传参的类型json
    public void getCustomerStructureInfo(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TCustomerInfoQueryReq req = request.parseObject(request.getString("req"), TCustomerInfoQueryReq.class);
        TCustomerStructureInfoResult customerStructureInfo = null;
        try {
            customerStructureInfo = customerThriftService.getCustomerStructureInfo(req);
            logger.info(customerStructureInfo);
            AssertUtil.assertByCompareJSONLenient(customerStructureInfo,expect);
        } catch (TException e) {
            logger.error("接口返回值中Required field 'url'= null (这是一个遗留问题,请重点关注)");
        }

    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "批量剔除门店",dataProvider = "json-ext") //case名称,传参的类型json
    public void batchRemovePoi(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TBatchRemoveCustomerPoiReq req = request.parseObject(request.getString("req"), TBatchRemoveCustomerPoiReq.class);
        TBatchRemoveCustomerPoiResult tBatchRemoveCustomerPoiResult = customerThriftService.batchRemovePoi(req);
        logger.info(tBatchRemoveCustomerPoiResult);
        AssertUtil.assertByCompareJSONLenient(tBatchRemoveCustomerPoiResult,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "批量分配负责人",dataProvider = "json-ext") //case名称,传参的类型json
    public void batchAssignStakeholder(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TCustomerStakeholerImportReq req = request.parseObject(request.getString("req"), TCustomerStakeholerImportReq.class);
        TCustomerStakeholerImportResult tCustomerStakeholerImportResult = customerThriftService.batchAssignStakeholder(req);
        logger.info(tCustomerStakeholerImportResult);
        AssertUtil.assertByCompareJSONLenient(tCustomerStakeholerImportResult,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "模糊查询客户",dataProvider = "json-ext") //case名称,传参的类型json
    public void fuzzyQueryCostomer(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        int operatorId = Integer.parseInt(request.getString("operatorId"));
        FuzzyQueryCostomerReq req = request.parseObject(request.getString("req"), FuzzyQueryCostomerReq.class);
        FuzzyQueryCostomerResp fuzzyQueryCostomerResp = customerThriftService.fuzzyQueryCostomer(operatorId, req);
        logger.info(fuzzyQueryCostomerResp);
        AssertUtil.assertByCompareJSONLenient(fuzzyQueryCostomerResp,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "查询门店详细信息",dataProvider = "json-ext") //case名称,传参的类型json
    public void getPoiDetails(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        int poiId = Integer.parseInt(request.getString("poiId"));
        TPoiDetailsResult poiDetails = null;
        try {
            poiDetails = customerThriftService.getPoiDetails(poiId);
            logger.info(poiDetails);
            AssertUtil.assertByCompareJSONLenient(poiDetails,expect);
        } catch (TException e) {
            logger.error("接口返回值中Required field 'pingxinHqs'= null (这是一个遗留问题,请重点关注)");
        }
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "查询总部对应的品牌",dataProvider = "json-ext") //case名称,传参的类型json
    public void queryAllBrandWithMerchantNo(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        THqNoAndBizLineDTO hqNoAndBizLines = request.parseObject(request.getString("hqNoAndBizLines"), THqNoAndBizLineDTO.class);
        TBrandQueryResult tBrandQueryResult = customerThriftService.queryAllBrandWithMerchantNo(hqNoAndBizLines);
        logger.info(tBrandQueryResult);
        AssertUtil.assertByCompareJSONLenient(tBrandQueryResult,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "使用品牌id查询所有总部",dataProvider = "json-ext") //case名称,传参的类型json
    public void queryAllHeadquarterWithBrandId(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        long mtBrandId = Long.parseLong(request.getString("mtBrandId"));
        THeadquaterQueryResult tHeadquaterQueryResult = customerThriftService.queryAllHeadquarterWithBrandId(mtBrandId);
        logger.info(tHeadquaterQueryResult);
        AssertUtil.assertByCompareJSONLenient(tHeadquaterQueryResult,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "计算并查询客户门店",dataProvider = "json-ext") //case名称,传参的类型json
    public void computeAndQueryCustomerPois(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TCustomerPoiQueryReq req = request.parseObject(request.getString("req"), TCustomerPoiQueryReq.class);
        List<TCustomerRuleDTO> rules = request.parseArray(request.getString("rules"), TCustomerRuleDTO.class);
        TPage page = request.parseObject(request.getString("page"), TPage.class);
        TCustomerPoiPageResult tCustomerPoiPageResult = customerThriftService.computeAndQueryCustomerPois(req, rules, page);
        logger.info(tCustomerPoiPageResult);
        AssertUtil.assertByCompareJSONLenient(tCustomerPoiPageResult,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "excel表格导入",dataProvider = "json-ext") //case名称,传参的类型json
    public void importExcel(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TImportExcelReq req = request.parseObject(request.getString("req"), TImportExcelReq.class);
        TContext context = request.parseObject(request.getString("context"), TContext.class);
        TExcelUrlKeyResult tExcelUrlKeyResult = excelThriftService.importExcel(req, context);
        logger.info(tExcelUrlKeyResult);
        AssertUtil.assertByCompareJSONLenient(tExcelUrlKeyResult,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "通过urlkey换取excel_url",dataProvider = "json-ext") //case名称,传参的类型json
    public void getExcelUrl(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        String urlKey = request.getString("urlKey");
        TContext context = request.parseObject(request.getString("context"), TContext.class);
        TExcelUrlResult excelUrl = excelThriftService.getExcelUrl(urlKey, context);
        logger.info(excelUrl);
        AssertUtil.assertByCompareJSONLenient(excelUrl,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "客户信息导出",dataProvider = "json-ext") //case名称,传参的类型json
    public void exportCustomers(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        com.sankuai.meituan.zcm.component.customer.thrift.model.TCustomerQueryReq req = request.parseObject(request.getString("req"), com.sankuai.meituan.zcm.component.customer.thrift.model.TCustomerQueryReq.class);
        TContext context = request.parseObject(request.getString("context"), TContext.class);
        TBoolResult tBoolResult = excelThriftService.exportCustomers(req, context);
        logger.info(tBoolResult);
        AssertUtil.assertByCompareJSONLenient(tBoolResult,expect);
    }

    @Contributor(owner = "tanxiaodong05@meituan.com") //编写者
    @Test(description = "操作日志",dataProvider = "json-ext") //case名称,传参的类型json
    public void queryCustomerUnitLogV2(JSONObject preconditions, String comments, JSONObject request, JSONObject expect, JSONObject ext) throws Exception{
        TPageQueryCustomerUnitLogsReq req = request.parseObject(request.getString("req"), TPageQueryCustomerUnitLogsReq.class);
        TPageQueryCustomerUnitLogsResp tPageQueryCustomerUnitLogsResp = tCustomerUnitService.queryCustomerUnitLogV2(req);
        logger.info(tPageQueryCustomerUnitLogsResp);
        AssertUtil.assertByCompareJSONLenient(tPageQueryCustomerUnitLogsResp,expect);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值