package com.paic.yxd.aps.biz;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import mockit.Deencapsulation;
import mockit.Expectations;
import mockit.Mocked;
import mockit.NonStrictExpectations;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.web.client.RestOperations;
import com.alibaba.fastjson.JSON;
import com.paic.pafa.exceptions.BusinessException;
import com.paic.yxd.aps.common.service.BaseServiceExt;
import com.paic.yxd.aps.service.insurance.biz.InsuranceDateService;
import com.paic.yxd.aps.service.insurance.biz.InsuranceService;
import com.paic.yxd.aps.service.insurance.biz.impl.InsuranceServiceImpl;
import com.paic.yxd.aps.service.insurance.dto.InsuranceDateDto;
import com.paic.yxd.aps.service.insurance.dto.InsuranceMoneyData;
public class InsuranceServiceTest extends BizBaseTest {
@Resource(name = InsuranceService.SERVICE_ID)
private InsuranceService insuranceService;
//模拟私有方法
@Mocked(value={"getTotalInsuredAmount"})
InsuranceServiceImpl insuranceServiceImpl;
@Mocked
BaseServiceExt baseServiceExt;
@Resource
InsuranceDateService insuranceDateService;
/**
* 测试预保单
* @Description
* @author hedong
* @date 2016-11-16 上午10:12:13
* @modifyNote
* @throws BusinessException
*/
@SuppressWarnings("unchecked")
@Test
public void testGenerBeforehandInsurance() throws BusinessException{
new Expectations() {
{
/**
* 模拟私有方法
*/
Deencapsulation.invoke(insuranceServiceImpl,"getTotalInsuredAmount",anyString);
InsuranceMoneyData insuranceMoneyData=new InsuranceMoneyData(1010, 1000, 10);
result=insuranceMoneyData;
times=1;
}
{
//mock post方法
baseServiceExt.post((Map<String,Object>) withNotNull(), (RestOperations)withNotNull(), anyString);
Map<String,Object> resultMap=new HashMap<String,Object>();
Map<String,Object> insuranceResultMap=new HashMap<String,Object>();
insuranceResultMap.put("applyPolicyNo", "A001");
insuranceResultMap.put("noticeNo", "N001");
insuranceResultMap.put("totalInsuredAmount", "5000");
insuranceResultMap.put("totalActualPremium", "500");
insuranceResultMap.put("paymentEndDate", "2018-05-02");
resultMap.put("result", insuranceResultMap);
result=JSON.toJSONString(resultMap);
times=1;
}
};
Map<String, Object> param = getBeforInsuranceInputPara();
Map<String, Object> map=insuranceService.generBeforehandInsurance(param);
System.out.println(map);
Assert.assertNotNull(map);
}
/**
* 预保单入参
* @Description
* @author hedong
* @date 2016-11-21 上午11:05:27
* @modifyNote
* @return 预保单入参
*/
private Map<String, Object> getBeforInsuranceInputPara() {
Map<String, Object> param=new HashMap<String, Object>();
param.put("systemId", "好车主");
param.put("systemFlowId", "12123");
//测试环境11111 开发环境FDSAFG89428490328
param.put("applicationNo", "test201600717970");
param.put("personnelType", "1");
param.put("name", "张三");
param.put("certificateType", "01");
param.put("certificateNo", "5100000000000000000X");
param.put("linkManName", "张思");
param.put("birthday", "2011-01-01");
param.put("sexCode", "M");
param.put("nationality", "中国");
param.put("mobileTelephone", "18888888888");
param.put("officeTelephone", "028-88888");
param.put("homeTelephone", "18888888899");
param.put("totalInsuredAmount", "10000");
param.put("totalActualPremium", "100");
param.put("expectRate", "0.1");
List<Map<String,Object>> riskPropertyInfoList=new ArrayList<Map<String,Object>>();
Map<String, Object> m1=new HashMap<String, Object>();
m1.put("applyNum", "1");
m1.put("applyNo", "1111");
m1.put("productNo", "3000100010001");
m1.put("applyCity", "盐亭县");
m1.put("loanAmount", "10000");
m1.put("loanInterest", "100");
m1.put("loanTimeLimit", "12");
riskPropertyInfoList.add(m1);
param.put("riskPropertyInfoList", riskPropertyInfoList);
return param;
}
/**
* 测试正式保单
* @Description
* @author hedong
* @date 2016-11-16 上午10:12:32
* @modifyNote
*/
@SuppressWarnings("unchecked")
@Test
public void testGenerateFormalInsurance(){
new NonStrictExpectations(insuranceDateService) {
{
insuranceDateService.getInsuranceDateDto(anyString, anyString);
result=new InsuranceDateDto(new Date(), new Date(), new Date(), new Date());
}
{
//mock post方法
baseServiceExt.post((Map<String, Object>)any, (RestOperations)any, anyString);
result="{\"responseCode\":\"999999\",\"responseMsg\":\"成功\",\"result\":{\"applyPolicyNo\":\"52696023900014779010\",\"policyNo\":\"12696023900011008630\"}}";
}
};
insuranceService.generateFormalInsurance(null);
}
}
复制代码
Jmockit 初体验【版本1.6】
最新推荐文章于 2022-10-24 21:41:40 发布