003、Service单测(方式2)

1. 项目代码

能够正常断点到service代码

pom.xml

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

BizTest

package com.xxx.xx.store.proxy;

import com.google.common.collect.Sets;
import com.xxx.xx.model.dto.store.StoreInformationDto;
import com.xxx.xx.store.LocalBasedTest;
import com.xxx.xx.store.proxy.liststoresuserisspecifiedrole.ListStoresUserIsSpecifiedRoleProxy;
import com.xxx.xx.store.proxy.liststoresuserisspecifiedrole.ListStoresUserIsSpecifiedRoleProxyFactory;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.Test;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 */
@Slf4j
public class ListStoresUserIsSpecifiedRoleNewProxyTest extends LocalBasedTest {

    @Resource
    private ListStoresUserIsSpecifiedRoleProxyFactory listStoresUserIsSpecifiedRoleProxyFactory;

    @Test
    public void test4New() {
//        new
//        switch.proxySwitch = "true";
        ListStoresUserIsSpecifiedRoleProxy proxy = listStoresUserIsSpecifiedRoleProxyFactory.getProxy();
        String userAccount = "22064536";
        Set<String> roleCodes = Sets.newHashSet("hpc_pre_role_admin", "xx_store_admin", "10002123134");
        boolean isNew = true;
        List<StoreInformationDto> newResult = proxy.listStoresUserIsSpecifiedRole(userAccount, roleCodes, isNew);
        // SELECT DISTINCT oor.xw_code, oor.xw_name, oor.xw_master, oor.xw_master_name, oor.bu_name, oor.bu_code, oor.bu_master, oor.bu_master_name, oor.pt_name, oor.pt_code FROM ods_org oor WHERE oor.xw_status = 1 and oor.xw_code in ( 'XX' )
        Assert.assertNotNull(newResult);
        // 根据用户查询出的storeId集合获取在哪些门店下有这个角色  结果校验
        log.info("newResult:\n{}", newResult);
    }

    @Test
    public void test4Old() {
//        old
//        switch.proxySwitch = "false";
        String userAccount = "001";
        Set<String> roleCodes = Sets.newHashSet("hpc_pre_role_admin", "xx_store_admin", "10002123134");
        boolean isNew = true;

        ListStoresUserIsSpecifiedRoleProxy proxy = listStoresUserIsSpecifiedRoleProxyFactory.getProxy();
        List<StoreInformationDto> oldResult = proxy.listStoresUserIsSpecifiedRole(userAccount, roleCodes, isNew);
        Assert.assertNotNull(oldResult);
        // 根据用户查询出的storeId集合获取在哪些门店下有这个角色  结果校验
        log.info("oldResult:\n{}", oldResult);
    }
}

LocalBasedTest

package com.xxx.xx.store;

import com.xxx.xx.xxStoreApplication;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
 * 本地集成测试可以继承这个类
 *
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = xxStoreApplication.class)
@ActiveProfiles("dev")
public abstract class LocalBasedTest {

    @Before
    public void before() {

    }
}

2. 权限单元测试结果验证

ListStoresUserIsSpecifiedRoleNewProxyTest

结论:相同参数,old和new两次查询的结果相同。

New

newResult:
[StoreInformationDto(xwCode=XX, xwName=XXXX, xwMaster=XX, xwMasterName=XX, buName=XX, buCode=XX, buMaster=XX, buMasterName=XX, ptName=XX, ptCode=XX, province=null, city=null, district=null, telephone=null, address=null, longitude=null, latitude=null, merchantLogoPicUrl=null, merchantPhotoUrl=null, publicityVideoUrl=null, flowableKey=null, flowableNodeConfig=null, hrpcKey=null, legalPerson=null, legalPersonIdNumber=null, businessLicenseNumber=null, businessLicenseUrl=null, idFrontPicUrl=null, idBackPicUrl=null, updatePerson=null, updateTime=null, provinceName=null, cityName=null, districtName=null, wgs84=null, gcj02=null)]

Old

oldResult:
[StoreInformationDto(xwCode=X000007XX, xwName=XXX, xwMaster=XX, xwMasterName=XX, buName=XX, buCode=38, buMaster=XX, buMasterName=XX, ptName=XX, ptCode=, province=null, city=null, district=null, telephone=null, address=null, longitude=null, latitude=null, merchantLogoPicUrl=null, merchantPhotoUrl=null, publicityVideoUrl=null, flowableKey=null, flowableNodeConfig=null, hrpcKey=null, legalPerson=null, legalPersonIdNumber=null, businessLicenseNumber=null, businessLicenseUrl=null, idFrontPicUrl=null, idBackPicUrl=null, updatePerson=null, updateTime=null, provinceName=null, cityName=null, districtName=null, wgs84=null, gcj02=null)]

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值