@Transactional public void removePendingFund(final String transactionHash) { pendingFundRepository.findByTransactionHash(transactionHash).ifPresent(pendingFundRepository::delete); }
@Test public void saveFunds() { final Request request = RequestMother.freeCodeCampNoUserStories().build(); final FundsAddedCommand command = FundsAddedCommand.builder() .requestId(request.getId()) .amountInWei(BigDecimal.TEN) .blockchainEventId(465L) .transactionHash("trans_hash") .funderAddress("address") .timestamp(LocalDateTime.now()) .token("token") .build(); final FundDto fundDto = FundDtoMother.aFundDto().build(); final RequestDto requestDto = new RequestDto(); final Cache cache = mock(Cache.class); when(requestRepository.findOne(request.getId())).thenReturn(Optional.of(request)); when(mappers.map(eq(Fund.class), eq(FundDto.class), any(Fund.class))).thenReturn(fundDto); when(mappers.map(eq(Request.class), eq(RequestDto.class), any(Request.class))).thenReturn(requestDto); when(cacheManager.getCache("funds")).thenReturn(cache); when(pendingFundRepository.findByTransactionHash(command.getTransactionHash())).thenReturn(Optional.of(PendingFund.builder().userId(funder.getName()).build())); fundService.addFunds(command); verifyFundsSaved(command, funder); verifyEventCreated(request.getId(), fundDto); verify(cache).evict(request.getId()); }
@Override @Transactional public void addFunds(final FundsAddedCommand command) { final Fund.FundBuilder fundBuilder = Fund.builder() .tokenValue(TokenValue.builder() .amountInWei(command.getAmountInWei()) .tokenAddress(command.getToken()) .build()) .requestId(command.getRequestId()) .timestamp(command.getTimestamp()) .funderAddress(command.getFunderAddress()) .blockchainEventId(command.getBlockchainEventId()); final Optional<PendingFund> pendingFund = pendingFundRepository.findByTransactionHash(command.getTransactionHash()); if (pendingFund.isPresent()) { fundBuilder.funderUserId(pendingFund.get().getUserId()); } final Fund fund = fundRepository.saveAndFlush(fundBuilder.build()); cacheManager.getCache("funds").evict(fund.getRequestId()); eventPublisher.publishEvent(RequestFundedEvent.builder() .fundDto(mappers.map(Fund.class, FundDto.class, fund)) .requestId(command.getRequestId()) .timestamp(command.getTimestamp()) .build()); }