@Test public void getTotalFundsForRequest() { final long requestId = 6457L; final Request request = RequestMother.fundRequestArea51().withStatus(RequestStatus.FUNDED).build(); final IssueInformation issueInformation = request.getIssueInformation(); final String platform = issueInformation.getPlatform().name(); final String platformId = issueInformation.getPlatformId(); final String tokenAddress1 = "0x64576fg"; final String tokenAddress2 = "0x654fh987"; final BigDecimal fndAmount = new BigDecimal("324"); final BigDecimal zrxAmount = new BigDecimal("762"); final TokenValueDto fndTokenValue = TokenValueDtoMother.FND().totalAmount(fndAmount).build(); final TokenValueDto zrxTokenValue = TokenValueDtoMother.ZRX().totalAmount(zrxAmount).build(); when(requestRepository.findOne(requestId)).thenReturn(Optional.of(request)); when(fundRequestContractsService.fundRepository().getFundedTokenCount(platform, platformId)).thenReturn(2L); when(fundRequestContractsService.fundRepository().getFundedToken(platform, platformId, 0L)).thenReturn(Optional.of(tokenAddress1)); when(fundRequestContractsService.fundRepository().getFundedToken(platform, platformId, 1L)).thenReturn(Optional.of(tokenAddress2)); when(fundRequestContractsService.fundRepository().balance(platform, platformId, tokenAddress1)).thenReturn(fndAmount.toBigInteger()); when(fundRequestContractsService.fundRepository().balance(platform, platformId, tokenAddress2)).thenReturn(zrxAmount.toBigInteger()); when(tokenValueMapper.map(tokenAddress1, fndAmount)).thenReturn(fndTokenValue); when(tokenValueMapper.map(tokenAddress2, zrxAmount)).thenReturn(zrxTokenValue); final List<TokenValueDto> result = fundService.getTotalFundsForRequest(requestId); assertThat(result).containsExactlyInAnyOrder(fndTokenValue, zrxTokenValue); }
@Override @Transactional(readOnly = true) @Cacheable(value = "funds", key = "#requestId", unless = "#result.isEmpty()") public List<TokenValueDto> getTotalFundsForRequest(Long requestId) { final Optional<Request> one = requestRepository.findOne(requestId); if (one.isPresent()) { try { if (one.get().getStatus() == RequestStatus.CLAIMED) { return getFromClaimRepository(one.get()); } else { return getFromFundRepository(one.get()); } } catch (final Exception ex) { return Collections.emptyList(); } } else { return Collections.emptyList(); } }
FundServiceImpl implements FundService { @Override @Transactional(readOnly = true) @Cacheable(value = "funds", key = "#requestId", unless = "#result.isEmpty()") public List<TokenValueDto> getTotalFundsForRequest(Long requestId) { final Optional<Request> one = requestRepository.findOne(requestId); if (one.isPresent()) { try { if (one.get().getStatus() == RequestStatus.CLAIMED) { return getFromClaimRepository(one.get()); } else { return getFromFundRepository(one.get()); } } catch (final Exception ex) { return Collections.emptyList(); } } else { return Collections.emptyList(); } } }
FundServiceImpl implements FundService { @Override @Transactional(readOnly = true) @Cacheable(value = "funds", key = "#requestId", unless = "#result.isEmpty()") public List<TokenValueDto> getTotalFundsForRequest(Long requestId) { final Optional<Request> one = requestRepository.findOne(requestId); if (one.isPresent()) { try { if (one.get().getStatus() == RequestStatus.CLAIMED) { return getFromClaimRepository(one.get()); } else { return getFromFundRepository(one.get()); } } catch (final Exception ex) { return Collections.emptyList(); } } else { return Collections.emptyList(); } } @Autowired  FundServiceImpl(final FundRepository fundRepository,
                           final RefundRepository refundRepository,
                           final PendingFundRepository pendingFundRepository,
                           final RequestRepository requestRepository,
                           final Mappers mappers,
                           final ApplicationEventPublisher eventPublisher,
                           final CacheManager cacheManager,
                           final FundRequestContractsService fundRequestContractsService,
                           final FiatService fiatService,
                           final TokenValueMapper tokenValueMapper,
                           final FundFundsByFunderAggregator fundFundsByFunderAggregator,
                           final RefundFundsByFunderAggregator refundFundsByFunderAggregator,
                           final FundsAndRefundsAggregator fundsAndRefundsAggregator); }
FundServiceImpl implements FundService { @Override @Transactional(readOnly = true) @Cacheable(value = "funds", key = "#requestId", unless = "#result.isEmpty()") public List<TokenValueDto> getTotalFundsForRequest(Long requestId) { final Optional<Request> one = requestRepository.findOne(requestId); if (one.isPresent()) { try { if (one.get().getStatus() == RequestStatus.CLAIMED) { return getFromClaimRepository(one.get()); } else { return getFromFundRepository(one.get()); } } catch (final Exception ex) { return Collections.emptyList(); } } else { return Collections.emptyList(); } } @Autowired  FundServiceImpl(final FundRepository fundRepository,
                           final RefundRepository refundRepository,
                           final PendingFundRepository pendingFundRepository,
                           final RequestRepository requestRepository,
                           final Mappers mappers,
                           final ApplicationEventPublisher eventPublisher,
                           final CacheManager cacheManager,
                           final FundRequestContractsService fundRequestContractsService,
                           final FiatService fiatService,
                           final TokenValueMapper tokenValueMapper,
                           final FundFundsByFunderAggregator fundFundsByFunderAggregator,
                           final RefundFundsByFunderAggregator refundFundsByFunderAggregator,
                           final FundsAndRefundsAggregator fundsAndRefundsAggregator); @Transactional(readOnly = true) @Override List<FundDto> findAll(); @Transactional(readOnly = true) @Override List<FundDto> findAll(Iterable<Long> ids); @Override @Transactional(readOnly = true) FundDto findOne(Long id); @Override @Transactional(readOnly = true) @Cacheable(value = "funds", key = "#requestId", unless = "#result.isEmpty()") List<TokenValueDto> getTotalFundsForRequest(Long requestId); @Override @Transactional(readOnly = true) FundsForRequestDto getFundsForRequestGroupedByFunder(final Long requestId); @Override @CacheEvict(value = "funds", key = "#requestId") void clearTotalFundsCache(Long requestId); @Override @Transactional void addFunds(final FundsAddedCommand command); @Override Optional<TokenValueDto> getFundsFor(final Long requestId, final String funderAddress, final String tokenAddress); }
FundServiceImpl implements FundService { @Override @Transactional(readOnly = true) @Cacheable(value = "funds", key = "#requestId", unless = "#result.isEmpty()") public List<TokenValueDto> getTotalFundsForRequest(Long requestId) { final Optional<Request> one = requestRepository.findOne(requestId); if (one.isPresent()) { try { if (one.get().getStatus() == RequestStatus.CLAIMED) { return getFromClaimRepository(one.get()); } else { return getFromFundRepository(one.get()); } } catch (final Exception ex) { return Collections.emptyList(); } } else { return Collections.emptyList(); } } @Autowired  FundServiceImpl(final FundRepository fundRepository,
                           final RefundRepository refundRepository,
                           final PendingFundRepository pendingFundRepository,
                           final RequestRepository requestRepository,
                           final Mappers mappers,
                           final ApplicationEventPublisher eventPublisher,
                           final CacheManager cacheManager,
                           final FundRequestContractsService fundRequestContractsService,
                           final FiatService fiatService,
                           final TokenValueMapper tokenValueMapper,
                           final FundFundsByFunderAggregator fundFundsByFunderAggregator,
                           final RefundFundsByFunderAggregator refundFundsByFunderAggregator,
                           final FundsAndRefundsAggregator fundsAndRefundsAggregator); @Transactional(readOnly = true) @Override List<FundDto> findAll(); @Transactional(readOnly = true) @Override List<FundDto> findAll(Iterable<Long> ids); @Override @Transactional(readOnly = true) FundDto findOne(Long id); @Override @Transactional(readOnly = true) @Cacheable(value = "funds", key = "#requestId", unless = "#result.isEmpty()") List<TokenValueDto> getTotalFundsForRequest(Long requestId); @Override @Transactional(readOnly = true) FundsForRequestDto getFundsForRequestGroupedByFunder(final Long requestId); @Override @CacheEvict(value = "funds", key = "#requestId") void clearTotalFundsCache(Long requestId); @Override @Transactional void addFunds(final FundsAddedCommand command); @Override Optional<TokenValueDto> getFundsFor(final Long requestId, final String funderAddress, final String tokenAddress);  }