@Test public void refundProcessed_firstEvent() { final long requestId = 644L; final String amount = "4530000000000000000"; final String tokenHash = "0x05466"; final String funderAddress = "0x67879809"; final long blockchainEventId = 34L; final String transactionHash = "0x46578"; final String requestedBy = "gfhchj"; final RefundRequest refundRequest1 = mock(RefundRequest.class); final RefundRequest refundRequest2 = mock(RefundRequest.class); final List<RefundRequest> refundRequests = Arrays.asList(refundRequest1, refundRequest2); final Cache fundsCache = mock(Cache.class); final Refund expected = Refund.builder() .requestId(requestId) .tokenValue(TokenValue.builder() .amountInWei(new BigDecimal(amount)) .tokenAddress(tokenHash) .build()) .funderAddress(funderAddress) .blockchainEventId(blockchainEventId) .requestedBy(requestedBy) .build(); when(refundRequest1.getRequestedBy()).thenReturn(requestedBy); when(refundRequestRepository.findAllByRequestIdAndStatusIn(requestId, APPROVED)).thenReturn(refundRequests); when(cacheManager.getCache("funds")).thenReturn(fundsCache); refundService.refundProcessed(RefundProcessedCommand.builder() .requestId(requestId) .amount(amount) .tokenHash(tokenHash) .funderAddress(funderAddress) .blockchainEventId(blockchainEventId) .transactionHash(transactionHash) .build()); final InOrder inOrder = inOrder(refundRepository, fundsCache, applicationEventPublisher); inOrder.verify(refundRepository).save(expected); inOrder.verify(fundsCache).evict(requestId); inOrder.verify(applicationEventPublisher).publishEvent(new RefundProcessedEvent(expected)); verify(refundRequest1).setTransactionHash(transactionHash); verify(refundRequest1).setStatus(PROCESSED); verify(refundRequest2).setTransactionHash(transactionHash); verify(refundRequest2).setStatus(PROCESSED); verify(refundRequestRepository).save(refundRequests); }
@Override @Transactional public void refundProcessed(final RefundProcessedCommand command) { final List<RefundRequest> refundRequests = refundRequestRepository.findAllByRequestIdAndStatusIn(command.getRequestId(), APPROVED); refundRequests.forEach(refundRequest -> { refundRequest.setStatus(PROCESSED); refundRequest.setTransactionHash(command.getTransactionHash()); }); refundRequestRepository.save(refundRequests); final Refund refund = Refund.builder() .requestId(command.getRequestId()) .funderAddress(command.getFunderAddress()) .blockchainEventId(command.getBlockchainEventId()) .requestedBy(resolveRequestedBy(command, refundRequests).orElse(null)) .tokenValue(TokenValue.builder() .amountInWei(new BigDecimal(command.getAmount())) .tokenAddress(command.getTokenHash()) .build()) .build(); refundRepository.save(refund); cacheManager.getCache ("funds").evict(command.getRequestId()); applicationEventPublisher.publishEvent(new RefundProcessedEvent(refund)); }
RefundServiceImpl implements RefundService { @Override @Transactional public void refundProcessed(final RefundProcessedCommand command) { final List<RefundRequest> refundRequests = refundRequestRepository.findAllByRequestIdAndStatusIn(command.getRequestId(), APPROVED); refundRequests.forEach(refundRequest -> { refundRequest.setStatus(PROCESSED); refundRequest.setTransactionHash(command.getTransactionHash()); }); refundRequestRepository.save(refundRequests); final Refund refund = Refund.builder() .requestId(command.getRequestId()) .funderAddress(command.getFunderAddress()) .blockchainEventId(command.getBlockchainEventId()) .requestedBy(resolveRequestedBy(command, refundRequests).orElse(null)) .tokenValue(TokenValue.builder() .amountInWei(new BigDecimal(command.getAmount())) .tokenAddress(command.getTokenHash()) .build()) .build(); refundRepository.save(refund); cacheManager.getCache ("funds").evict(command.getRequestId()); applicationEventPublisher.publishEvent(new RefundProcessedEvent(refund)); } }
RefundServiceImpl implements RefundService { @Override @Transactional public void refundProcessed(final RefundProcessedCommand command) { final List<RefundRequest> refundRequests = refundRequestRepository.findAllByRequestIdAndStatusIn(command.getRequestId(), APPROVED); refundRequests.forEach(refundRequest -> { refundRequest.setStatus(PROCESSED); refundRequest.setTransactionHash(command.getTransactionHash()); }); refundRequestRepository.save(refundRequests); final Refund refund = Refund.builder() .requestId(command.getRequestId()) .funderAddress(command.getFunderAddress()) .blockchainEventId(command.getBlockchainEventId()) .requestedBy(resolveRequestedBy(command, refundRequests).orElse(null)) .tokenValue(TokenValue.builder() .amountInWei(new BigDecimal(command.getAmount())) .tokenAddress(command.getTokenHash()) .build()) .build(); refundRepository.save(refund); cacheManager.getCache ("funds").evict(command.getRequestId()); applicationEventPublisher.publishEvent(new RefundProcessedEvent(refund)); } RefundServiceImpl(final RefundRequestRepository refundRequestRepository,
                             final RefundRepository refundRepository,
                             final RefundRequestDtoMapper refundRequestDtoMapper,
                             final CacheManager cacheManager,
                             final ApplicationEventPublisher applicationEventPublisher); }
RefundServiceImpl implements RefundService { @Override @Transactional public void refundProcessed(final RefundProcessedCommand command) { final List<RefundRequest> refundRequests = refundRequestRepository.findAllByRequestIdAndStatusIn(command.getRequestId(), APPROVED); refundRequests.forEach(refundRequest -> { refundRequest.setStatus(PROCESSED); refundRequest.setTransactionHash(command.getTransactionHash()); }); refundRequestRepository.save(refundRequests); final Refund refund = Refund.builder() .requestId(command.getRequestId()) .funderAddress(command.getFunderAddress()) .blockchainEventId(command.getBlockchainEventId()) .requestedBy(resolveRequestedBy(command, refundRequests).orElse(null)) .tokenValue(TokenValue.builder() .amountInWei(new BigDecimal(command.getAmount())) .tokenAddress(command.getTokenHash()) .build()) .build(); refundRepository.save(refund); cacheManager.getCache ("funds").evict(command.getRequestId()); applicationEventPublisher.publishEvent(new RefundProcessedEvent(refund)); } RefundServiceImpl(final RefundRequestRepository refundRequestRepository,
                             final RefundRepository refundRepository,
                             final RefundRequestDtoMapper refundRequestDtoMapper,
                             final CacheManager cacheManager,
                             final ApplicationEventPublisher applicationEventPublisher); @Override @Transactional void requestRefund(final RequestRefundCommand requestRefundCommand); @Override @Transactional(readOnly = true) List<RefundRequestDto> findAllRefundRequestsFor(final long requestId, final RefundRequestStatus... statuses); @Override @Transactional(readOnly = true) List<RefundRequestDto> findAllRefundRequestsFor(final long requestId, final String funderAddress, final RefundRequestStatus status); @Override @Transactional void refundProcessed(final RefundProcessedCommand command); }
RefundServiceImpl implements RefundService { @Override @Transactional public void refundProcessed(final RefundProcessedCommand command) { final List<RefundRequest> refundRequests = refundRequestRepository.findAllByRequestIdAndStatusIn(command.getRequestId(), APPROVED); refundRequests.forEach(refundRequest -> { refundRequest.setStatus(PROCESSED); refundRequest.setTransactionHash(command.getTransactionHash()); }); refundRequestRepository.save(refundRequests); final Refund refund = Refund.builder() .requestId(command.getRequestId()) .funderAddress(command.getFunderAddress()) .blockchainEventId(command.getBlockchainEventId()) .requestedBy(resolveRequestedBy(command, refundRequests).orElse(null)) .tokenValue(TokenValue.builder() .amountInWei(new BigDecimal(command.getAmount())) .tokenAddress(command.getTokenHash()) .build()) .build(); refundRepository.save(refund); cacheManager.getCache ("funds").evict(command.getRequestId()); applicationEventPublisher.publishEvent(new RefundProcessedEvent(refund)); } RefundServiceImpl(final RefundRequestRepository refundRequestRepository,
                             final RefundRepository refundRepository,
                             final RefundRequestDtoMapper refundRequestDtoMapper,
                             final CacheManager cacheManager,
                             final ApplicationEventPublisher applicationEventPublisher); @Override @Transactional void requestRefund(final RequestRefundCommand requestRefundCommand); @Override @Transactional(readOnly = true) List<RefundRequestDto> findAllRefundRequestsFor(final long requestId, final RefundRequestStatus... statuses); @Override @Transactional(readOnly = true) List<RefundRequestDto> findAllRefundRequestsFor(final long requestId, final String funderAddress, final RefundRequestStatus status); @Override @Transactional void refundProcessed(final RefundProcessedCommand command);  }