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)]