@Test public void testReserve01() { TourInfo tour = new TourInfo("01"); DateTime depDay = now.withTime(0, 0, 0, 0).plusDays(7); tour.setDepDay(depDay.toDate()); tour.setTourDays(2); tour.setAvaRecMax(10); tour.setBasePrice(10000); tour.setAccommodation(new Accommodation()); tour.setDeparture(new Departure()); tour.setArrival(new Arrival()); when(tourInfoSharedService.findOneWithDetails("01")).thenReturn(tour); when(tourInfoSharedService.findOneWithDetailsForUpdate("01")) .thenReturn(tour); when(reserveRepository.countReservedPersonSumByTourInfo(tour .getTourCode())).thenReturn(7L); ReserveTourInput input = new ReserveTourInput(); input.setAdultCount(1); input.setChildCount(2); input.setTourCode("01"); input.setRemarks("aa"); PriceCalculateOutput priceCalculateOutput = new PriceCalculateOutput(); priceCalculateOutput.setSumPrice(100000); priceCalculateOutput.setAdultCount(1); priceCalculateOutput.setChildCount(2); when(priceCalculateSerivce.calculatePrice(10000, 1, 2)).thenReturn( priceCalculateOutput); ReserveTourOutput output = reserveService.reserve(input); ArgumentCaptor<Reserve> capture = ArgumentCaptor.forClass( Reserve.class); verify(reserveRepository, atLeast(1)).insert(capture.capture()); Reserve r = capture.getValue(); assertThat(output.getReserve(), is(r)); assertThat(r.getAdultCount(), is(1)); assertThat(r.getChildCount(), is(2)); assertThat(r.getSumPrice(), is(100000)); assertThat(r.getTourInfo().getTourCode(), is("01")); assertThat(r.getRemarks(), is("aa")); assertThat(r.getTransfer(), is(Reserve.NOT_TRANSFERED)); assertThat(r.getReservedDay(), is(now.withTime(0, 0, 0, 0).toDate())); }
@Override public ReserveTourOutput reserve( ReserveTourInput input) throws BusinessException { TourInfo tourInfo = tourInfoSharedService.findOneWithDetailsForUpdate( input.getTourCode()); DateTime today = dateFactory.newDateTime().withTime(0, 0, 0, 0); if (tourInfoSharedService.isOverPaymentLimit(tourInfo)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0004); throw new BusinessException(message); } int reserveMember = input.getAdultCount() + input.getChildCount(); int aveRecMax = tourInfo.getAvaRecMax(); Long sumCount = reserveRepository.countReservedPersonSumByTourInfo( tourInfo.getTourCode()); if (sumCount == null) { sumCount = 0L; } long vacantCount = aveRecMax - sumCount; log.debug("vacantCount({}), reserveMember({})", vacantCount, reserveMember); if (vacantCount < reserveMember) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0005); throw new BusinessException(message); } PriceCalculateOutput priceCalculateOutput = priceCalculateService .calculatePrice(tourInfo.getBasePrice(), input.getAdultCount(), input.getChildCount()); Reserve reserve = beanMapper.map(input, Reserve.class); reserve.setTourInfo(tourInfo); reserve.setSumPrice(priceCalculateOutput.getSumPrice()); reserve.setReservedDay(today.toDate()); reserve.setTransfer(Reserve.NOT_TRANSFERED); reserveRepository.insert(reserve); log.debug("reserved {}", reserve); ReserveTourOutput tourReserveOutput = new ReserveTourOutput(); tourReserveOutput.setPriceCalculateOutput(priceCalculateOutput); tourReserveOutput.setReserve(reserve); tourReserveOutput.setTourInfo(tourInfo); tourReserveOutput.setPaymentTimeLimit(tourInfo.getPaymentLimit() .toDate()); tourReserveOutput.setCustomer(input.getCustomer()); return tourReserveOutput; }
ReserveServiceImpl implements ReserveService { @Override public ReserveTourOutput reserve( ReserveTourInput input) throws BusinessException { TourInfo tourInfo = tourInfoSharedService.findOneWithDetailsForUpdate( input.getTourCode()); DateTime today = dateFactory.newDateTime().withTime(0, 0, 0, 0); if (tourInfoSharedService.isOverPaymentLimit(tourInfo)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0004); throw new BusinessException(message); } int reserveMember = input.getAdultCount() + input.getChildCount(); int aveRecMax = tourInfo.getAvaRecMax(); Long sumCount = reserveRepository.countReservedPersonSumByTourInfo( tourInfo.getTourCode()); if (sumCount == null) { sumCount = 0L; } long vacantCount = aveRecMax - sumCount; log.debug("vacantCount({}), reserveMember({})", vacantCount, reserveMember); if (vacantCount < reserveMember) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0005); throw new BusinessException(message); } PriceCalculateOutput priceCalculateOutput = priceCalculateService .calculatePrice(tourInfo.getBasePrice(), input.getAdultCount(), input.getChildCount()); Reserve reserve = beanMapper.map(input, Reserve.class); reserve.setTourInfo(tourInfo); reserve.setSumPrice(priceCalculateOutput.getSumPrice()); reserve.setReservedDay(today.toDate()); reserve.setTransfer(Reserve.NOT_TRANSFERED); reserveRepository.insert(reserve); log.debug("reserved {}", reserve); ReserveTourOutput tourReserveOutput = new ReserveTourOutput(); tourReserveOutput.setPriceCalculateOutput(priceCalculateOutput); tourReserveOutput.setReserve(reserve); tourReserveOutput.setTourInfo(tourInfo); tourReserveOutput.setPaymentTimeLimit(tourInfo.getPaymentLimit() .toDate()); tourReserveOutput.setCustomer(input.getCustomer()); return tourReserveOutput; } }
ReserveServiceImpl implements ReserveService { @Override public ReserveTourOutput reserve( ReserveTourInput input) throws BusinessException { TourInfo tourInfo = tourInfoSharedService.findOneWithDetailsForUpdate( input.getTourCode()); DateTime today = dateFactory.newDateTime().withTime(0, 0, 0, 0); if (tourInfoSharedService.isOverPaymentLimit(tourInfo)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0004); throw new BusinessException(message); } int reserveMember = input.getAdultCount() + input.getChildCount(); int aveRecMax = tourInfo.getAvaRecMax(); Long sumCount = reserveRepository.countReservedPersonSumByTourInfo( tourInfo.getTourCode()); if (sumCount == null) { sumCount = 0L; } long vacantCount = aveRecMax - sumCount; log.debug("vacantCount({}), reserveMember({})", vacantCount, reserveMember); if (vacantCount < reserveMember) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0005); throw new BusinessException(message); } PriceCalculateOutput priceCalculateOutput = priceCalculateService .calculatePrice(tourInfo.getBasePrice(), input.getAdultCount(), input.getChildCount()); Reserve reserve = beanMapper.map(input, Reserve.class); reserve.setTourInfo(tourInfo); reserve.setSumPrice(priceCalculateOutput.getSumPrice()); reserve.setReservedDay(today.toDate()); reserve.setTransfer(Reserve.NOT_TRANSFERED); reserveRepository.insert(reserve); log.debug("reserved {}", reserve); ReserveTourOutput tourReserveOutput = new ReserveTourOutput(); tourReserveOutput.setPriceCalculateOutput(priceCalculateOutput); tourReserveOutput.setReserve(reserve); tourReserveOutput.setTourInfo(tourInfo); tourReserveOutput.setPaymentTimeLimit(tourInfo.getPaymentLimit() .toDate()); tourReserveOutput.setCustomer(input.getCustomer()); return tourReserveOutput; }  }
ReserveServiceImpl implements ReserveService { @Override public ReserveTourOutput reserve( ReserveTourInput input) throws BusinessException { TourInfo tourInfo = tourInfoSharedService.findOneWithDetailsForUpdate( input.getTourCode()); DateTime today = dateFactory.newDateTime().withTime(0, 0, 0, 0); if (tourInfoSharedService.isOverPaymentLimit(tourInfo)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0004); throw new BusinessException(message); } int reserveMember = input.getAdultCount() + input.getChildCount(); int aveRecMax = tourInfo.getAvaRecMax(); Long sumCount = reserveRepository.countReservedPersonSumByTourInfo( tourInfo.getTourCode()); if (sumCount == null) { sumCount = 0L; } long vacantCount = aveRecMax - sumCount; log.debug("vacantCount({}), reserveMember({})", vacantCount, reserveMember); if (vacantCount < reserveMember) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0005); throw new BusinessException(message); } PriceCalculateOutput priceCalculateOutput = priceCalculateService .calculatePrice(tourInfo.getBasePrice(), input.getAdultCount(), input.getChildCount()); Reserve reserve = beanMapper.map(input, Reserve.class); reserve.setTourInfo(tourInfo); reserve.setSumPrice(priceCalculateOutput.getSumPrice()); reserve.setReservedDay(today.toDate()); reserve.setTransfer(Reserve.NOT_TRANSFERED); reserveRepository.insert(reserve); log.debug("reserved {}", reserve); ReserveTourOutput tourReserveOutput = new ReserveTourOutput(); tourReserveOutput.setPriceCalculateOutput(priceCalculateOutput); tourReserveOutput.setReserve(reserve); tourReserveOutput.setTourInfo(tourInfo); tourReserveOutput.setPaymentTimeLimit(tourInfo.getPaymentLimit() .toDate()); tourReserveOutput.setCustomer(input.getCustomer()); return tourReserveOutput; }  @Override Reserve findOneWithTourInfo(String reserveNo); @Override List<Reserve> findAllWithTourInfoByCustomer(String customerCode); @Override ReserveTourOutput reserve(
            ReserveTourInput input); @Override void cancel(String reserveNo); @Override ReservationUpdateOutput update(
            ReservationUpdateInput input); }
ReserveServiceImpl implements ReserveService { @Override public ReserveTourOutput reserve( ReserveTourInput input) throws BusinessException { TourInfo tourInfo = tourInfoSharedService.findOneWithDetailsForUpdate( input.getTourCode()); DateTime today = dateFactory.newDateTime().withTime(0, 0, 0, 0); if (tourInfoSharedService.isOverPaymentLimit(tourInfo)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0004); throw new BusinessException(message); } int reserveMember = input.getAdultCount() + input.getChildCount(); int aveRecMax = tourInfo.getAvaRecMax(); Long sumCount = reserveRepository.countReservedPersonSumByTourInfo( tourInfo.getTourCode()); if (sumCount == null) { sumCount = 0L; } long vacantCount = aveRecMax - sumCount; log.debug("vacantCount({}), reserveMember({})", vacantCount, reserveMember); if (vacantCount < reserveMember) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0005); throw new BusinessException(message); } PriceCalculateOutput priceCalculateOutput = priceCalculateService .calculatePrice(tourInfo.getBasePrice(), input.getAdultCount(), input.getChildCount()); Reserve reserve = beanMapper.map(input, Reserve.class); reserve.setTourInfo(tourInfo); reserve.setSumPrice(priceCalculateOutput.getSumPrice()); reserve.setReservedDay(today.toDate()); reserve.setTransfer(Reserve.NOT_TRANSFERED); reserveRepository.insert(reserve); log.debug("reserved {}", reserve); ReserveTourOutput tourReserveOutput = new ReserveTourOutput(); tourReserveOutput.setPriceCalculateOutput(priceCalculateOutput); tourReserveOutput.setReserve(reserve); tourReserveOutput.setTourInfo(tourInfo); tourReserveOutput.setPaymentTimeLimit(tourInfo.getPaymentLimit() .toDate()); tourReserveOutput.setCustomer(input.getCustomer()); return tourReserveOutput; }  @Override Reserve findOneWithTourInfo(String reserveNo); @Override List<Reserve> findAllWithTourInfoByCustomer(String customerCode); @Override ReserveTourOutput reserve(
            ReserveTourInput input); @Override void cancel(String reserveNo); @Override ReservationUpdateOutput update(
            ReservationUpdateInput input);  }