@Test public void statisticsReturnsMostFundedTechnology() { TokenAmountDto tokenAmount = new TokenAmountDto(fnd.getAddress(), EthUtil.toWei(BigDecimal.TEN, fnd.getDecimals())); TokenAmountDto tokenAmount2 = new TokenAmountDto(zrx.getAddress(), EthUtil.toWei(BigDecimal.ONE, zrx.getDecimals())); List<Object[]> requests = Arrays.asList( createObject("Java", fnd.getAddress(), tokenAmount.getTotalAmount()), createObject("Python", zrx.getAddress(), tokenAmount2.getTotalAmount()) ); when(fundRepository.getAmountPerTokenPerTechnologyWhereRequestHasStatusFunded()).thenReturn(requests); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(fnd.getSymbol()) .tokenAddress(fnd.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount.getTotalAmount(), fnd.getDecimals())) .build())).thenReturn(10.0); when(fiatService.getUsdPrice(TokenValueDto.builder() .tokenSymbol(zrx.getSymbol()) .tokenAddress(zrx.getAddress()) .totalAmount(EthUtil.fromWei(tokenAmount2.getTotalAmount(), zrx.getDecimals())) .build())).thenReturn(20.0); StatisticsDto result = statisticsService.getStatistics(); assertThat(result.getMostFundedTechnology()).isEqualTo("Python"); }
@Transactional(readOnly = true) @Override @Cacheable(value = "statistics", key = "'all'") public StatisticsDto getStatistics() { double totalAvailableFunding = fundRepository.getAmountPerTokenWhereRequestHasStatusFunded() .stream() .mapToDouble(this::mapToUsd) .sum(); String mostFundedProject = getMostFunded(fundRepository.getAmountPerTokenPerProjectWhereRequestHasStatusFunded()); String mostFundedTechnology = getMostFunded(fundRepository.getAmountPerTokenPerTechnologyWhereRequestHasStatusFunded()); return StatisticsDto.builder() .totalAvailableFunding(totalAvailableFunding) .mostFundedProject(mostFundedProject) .mostFundedTechnology(mostFundedTechnology) .build(); }
StatisticsServiceImpl implements StatisticsService { @Transactional(readOnly = true) @Override @Cacheable(value = "statistics", key = "'all'") public StatisticsDto getStatistics() { double totalAvailableFunding = fundRepository.getAmountPerTokenWhereRequestHasStatusFunded() .stream() .mapToDouble(this::mapToUsd) .sum(); String mostFundedProject = getMostFunded(fundRepository.getAmountPerTokenPerProjectWhereRequestHasStatusFunded()); String mostFundedTechnology = getMostFunded(fundRepository.getAmountPerTokenPerTechnologyWhereRequestHasStatusFunded()); return StatisticsDto.builder() .totalAvailableFunding(totalAvailableFunding) .mostFundedProject(mostFundedProject) .mostFundedTechnology(mostFundedTechnology) .build(); } }
StatisticsServiceImpl implements StatisticsService { @Transactional(readOnly = true) @Override @Cacheable(value = "statistics", key = "'all'") public StatisticsDto getStatistics() { double totalAvailableFunding = fundRepository.getAmountPerTokenWhereRequestHasStatusFunded() .stream() .mapToDouble(this::mapToUsd) .sum(); String mostFundedProject = getMostFunded(fundRepository.getAmountPerTokenPerProjectWhereRequestHasStatusFunded()); String mostFundedTechnology = getMostFunded(fundRepository.getAmountPerTokenPerTechnologyWhereRequestHasStatusFunded()); return StatisticsDto.builder() .totalAvailableFunding(totalAvailableFunding) .mostFundedProject(mostFundedProject) .mostFundedTechnology(mostFundedTechnology) .build(); } StatisticsServiceImpl(FundRepository fundRepository,
                                 TokenInfoService tokenInfoService,
                                 FiatService fiatService, CacheManager cacheManager); }
StatisticsServiceImpl implements StatisticsService { @Transactional(readOnly = true) @Override @Cacheable(value = "statistics", key = "'all'") public StatisticsDto getStatistics() { double totalAvailableFunding = fundRepository.getAmountPerTokenWhereRequestHasStatusFunded() .stream() .mapToDouble(this::mapToUsd) .sum(); String mostFundedProject = getMostFunded(fundRepository.getAmountPerTokenPerProjectWhereRequestHasStatusFunded()); String mostFundedTechnology = getMostFunded(fundRepository.getAmountPerTokenPerTechnologyWhereRequestHasStatusFunded()); return StatisticsDto.builder() .totalAvailableFunding(totalAvailableFunding) .mostFundedProject(mostFundedProject) .mostFundedTechnology(mostFundedTechnology) .build(); } StatisticsServiceImpl(FundRepository fundRepository,
                                 TokenInfoService tokenInfoService,
                                 FiatService fiatService, CacheManager cacheManager); @Transactional(readOnly = true) @Override @Cacheable(value = "statistics", key = "'all'") StatisticsDto getStatistics(); @TransactionalEventListener(phase = AFTER_COMMIT) @Transactional(propagation = REQUIRES_NEW, readOnly = true) void onFunded(RequestFundedEvent fundedEvent); @TransactionalEventListener(phase = AFTER_COMMIT) @Transactional(propagation = REQUIRES_NEW, readOnly = true) void onClaimed(RequestClaimedEvent claimedEvent); }
StatisticsServiceImpl implements StatisticsService { @Transactional(readOnly = true) @Override @Cacheable(value = "statistics", key = "'all'") public StatisticsDto getStatistics() { double totalAvailableFunding = fundRepository.getAmountPerTokenWhereRequestHasStatusFunded() .stream() .mapToDouble(this::mapToUsd) .sum(); String mostFundedProject = getMostFunded(fundRepository.getAmountPerTokenPerProjectWhereRequestHasStatusFunded()); String mostFundedTechnology = getMostFunded(fundRepository.getAmountPerTokenPerTechnologyWhereRequestHasStatusFunded()); return StatisticsDto.builder() .totalAvailableFunding(totalAvailableFunding) .mostFundedProject(mostFundedProject) .mostFundedTechnology(mostFundedTechnology) .build(); } StatisticsServiceImpl(FundRepository fundRepository,
                                 TokenInfoService tokenInfoService,
                                 FiatService fiatService, CacheManager cacheManager); @Transactional(readOnly = true) @Override @Cacheable(value = "statistics", key = "'all'") StatisticsDto getStatistics(); @TransactionalEventListener(phase = AFTER_COMMIT) @Transactional(propagation = REQUIRES_NEW, readOnly = true) void onFunded(RequestFundedEvent fundedEvent); @TransactionalEventListener(phase = AFTER_COMMIT) @Transactional(propagation = REQUIRES_NEW, readOnly = true) void onClaimed(RequestClaimedEvent claimedEvent);  }