实例:
/**Extension选择器*/
@Autowired
private ExtensionSelector extensionSelector;
/**明细Dao*/
@Autowired
private DetailDao detailDao;
@Override
public Map<String, Object> qryDetails(
QueryDetailVo qryDetail) {
logger.info("----------查询记录明细Serivce开始----------");
String id = qryDetail.getId();
String no = qryDetail.getNo();
String natural_key = qryDetail.getNatural_key();
Map<String, Object> resultMap = new HashMap<String, Object>();
//获取策略是否从本地获取记录明细
IDetailStrategy detailStrategy = extensionSelector
.getExtensionStrategy(id,StrategyName.DetailStrategy);
Map<String, Object> info = new HashMap<String, Object>();
Detail detail = new Detail();
detail.setNo(no);
detail.setDetail_status("2");
List<Detail> detailList = detailDao.getDetailListByNo(detail);
if(null != detailList && detailList.size() > 0){
info.put("create_time", detailList.get(0).getCreate_time());
info.put("id", id);
info.put("no", no);
}
Map<String, Object> detailStrategyMap = detailStrategy.detailRule(info);
if(null != detailStrategyMap.get("isDetailFromLocal") && (boolean)detailStrategyMap.get("isDetailFromLocal")){
List<DetailVo> localDetailList = detailDao.getDetails(id, natural_key);
resultMap.put(Constants.ROWS, localDetailList);
}
logger.info("----------查询记录明细Serivce结束----------");
return resultMap;
}
测试;
@Test
public void qryDetailsTest(){
IDetailService detailService = new DetailServiceImpl();
//输入参数
QueryDetailVo queryFee = new QueryDetailVo();
String id = "123";
String no = "85025fd80bcd2a";
String natural_key = "912639";
queryFee.setNatural_key(natural_key);
queryFee.setId(id);
queryFee.setNo(no);
Map<String, Object> map = new HashMap<String, Object>();
map.put("isDetailFromLocal", Boolean.TRUE);
List<Detail> detailList = new ArrayList<Detail>();
Detail detail = new Detail();
detail.setNatural_key(natural_key);
detail.setNo(no);
detail.setCreate_time(new Date());
detail.setDetail_status("2");
detailList.add(detail);
List<DetailVo> detaiVoList = new ArrayList<DetailVo>();
DetailVo detaiVo = new DetailVo();
detaiVo.setCreate_date(new Date());
detaiVo.setItem_name("测试项目");
detaiVo.setPrice("1800");
detaiVo.setNumber("10");
detaiVo.setTotle_amt("18000");
detaiVoList.add(detaiVo);
DetailDao detailDao = autowiredMockObject(outpatientFeeService, DetailDao.class);
IMocksControl mockExtensionSelector = EasyMock.createStrictControl();
ExtensionSelector extensionSelector = mockExtensionSelector.createMock(ExtensionSelector.class);
IMocksControl mock = EasyMock.createStrictControl();
IDetailStrategy detailStrategy = mock.createMock(IDetailStrategy.class);
//录制
EasyMock.expect(extensionSelector.getExtensionStrategy(id.intern(),StrategyName.DetailStrategy)).andReturn(paymentStrategy);
ReflectionTestUtils.setField(detailService, "extensionSelector", extensionSelector, ExtensionSelector.class);
EasyMock.expect(detailStrategy.detailRule(EasyMock.anyObject(Map.class))).andReturn(map);
EasyMock.expect(detailDao.getDetailListByNo(EasyMock.anyObject(Detail.class))).andReturn(detailList);
EasyMock.expect(detailDao.getFeeDetails(id, natural_key)).andReturn(detaiVoList);
//回放
EasyMock.replay(extensionSelector);
EasyMock.replay(detailStrategy);
EasyMock.replay(detailDao);
Map<String, Object> returnMap = detailService.qryDetails(queryFee);
System.out.println(returnMap);
}