@Test public void requestClaimed() { final RequestClaimedCommand command = new RequestClaimedCommand(); command.setTimestamp(LocalDateTime.now()); command.setSolver("davyvanroy"); command.setPlatform(Platform.GITHUB); command.setPlatformId("1"); command.setBlockchainEventId(6453L); final Request request = RequestMother.freeCodeCampNoUserStories().build(); final RequestDto requestDto = RequestDtoMother.freeCodeCampNoUserStories(); final ClaimDto claimDto = ClaimDtoMother.aClaimDto().build(); when(requestRepository.findByPlatformAndPlatformId(command.getPlatform(), command.getPlatformId())).thenReturn(Optional.of(request)); when(mappers.map(Request.class, RequestDto.class, request)).thenReturn(requestDto); when(mappers.map(eq(Claim.class), eq(ClaimDto.class), any(Claim.class))).thenReturn(claimDto); when(requestRepository.save(any(Request.class))).then(returnsFirstArg()); when(claimRepository.save(any(Claim.class))).then(returnsFirstArg()); requestService.requestClaimed(command); verifyClaimEventPublished(command, requestDto, claimDto); }
@Override @Transactional @CacheEvict(value = {"projects", "technologies"}, key = "'all'") public Request requestClaimed(RequestClaimedCommand command) { final Request request = updateStatus(requestRepository.findByPlatformAndPlatformId(command.getPlatform(), command.getPlatformId()) .orElseThrow(ResourceNotFoundException::new), RequestStatus.CLAIMED); Claim claim = claimRepository.save(ClaimBuilder.aClaim() .withRequestId(request.getId()) .withSolver(command.getSolver()) .withTimestamp(command.getTimestamp()) .withTokenValue(TokenValue.builder() .tokenAddress(command.getTokenHash()) .amountInWei(command.getAmountInWei()) .build()) .withBlockchainEventId(command.getBlockchainEventId()) .build()); eventPublisher.publishEvent(RequestClaimedEvent.builder() .blockchainEventId(command.getBlockchainEventId()) .requestDto(mappers.map(Request.class, RequestDto.class, request)) .claimDto(mappers.map(Claim.class, ClaimDto.class, claim)) .solver(command.getSolver()) .timestamp(command.getTimestamp()) .build()); return request; }
RequestServiceImpl implements RequestService { @Override @Transactional @CacheEvict(value = {"projects", "technologies"}, key = "'all'") public Request requestClaimed(RequestClaimedCommand command) { final Request request = updateStatus(requestRepository.findByPlatformAndPlatformId(command.getPlatform(), command.getPlatformId()) .orElseThrow(ResourceNotFoundException::new), RequestStatus.CLAIMED); Claim claim = claimRepository.save(ClaimBuilder.aClaim() .withRequestId(request.getId()) .withSolver(command.getSolver()) .withTimestamp(command.getTimestamp()) .withTokenValue(TokenValue.builder() .tokenAddress(command.getTokenHash()) .amountInWei(command.getAmountInWei()) .build()) .withBlockchainEventId(command.getBlockchainEventId()) .build()); eventPublisher.publishEvent(RequestClaimedEvent.builder() .blockchainEventId(command.getBlockchainEventId()) .requestDto(mappers.map(Request.class, RequestDto.class, request)) .claimDto(mappers.map(Claim.class, ClaimDto.class, claim)) .solver(command.getSolver()) .timestamp(command.getTimestamp()) .build()); return request; } }
RequestServiceImpl implements RequestService { @Override @Transactional @CacheEvict(value = {"projects", "technologies"}, key = "'all'") public Request requestClaimed(RequestClaimedCommand command) { final Request request = updateStatus(requestRepository.findByPlatformAndPlatformId(command.getPlatform(), command.getPlatformId()) .orElseThrow(ResourceNotFoundException::new), RequestStatus.CLAIMED); Claim claim = claimRepository.save(ClaimBuilder.aClaim() .withRequestId(request.getId()) .withSolver(command.getSolver()) .withTimestamp(command.getTimestamp()) .withTokenValue(TokenValue.builder() .tokenAddress(command.getTokenHash()) .amountInWei(command.getAmountInWei()) .build()) .withBlockchainEventId(command.getBlockchainEventId()) .build()); eventPublisher.publishEvent(RequestClaimedEvent.builder() .blockchainEventId(command.getBlockchainEventId()) .requestDto(mappers.map(Request.class, RequestDto.class, request)) .claimDto(mappers.map(Claim.class, ClaimDto.class, claim)) .solver(command.getSolver()) .timestamp(command.getTimestamp()) .build()); return request; } RequestServiceImpl(final RequestRepository requestRepository,
                              final Mappers mappers,
                              final GithubPlatformIdParser githubLinkParser,
                              final ProfileService profileService,
                              final ClaimRepository claimRepository,
                              final GithubGateway githubGateway,
                              final GithubClaimResolver githubClaimResolver,
                              final ApplicationEventPublisher eventPublisher,
                              final Erc67Generator erc67Generator,
                              final Environment environment); }
RequestServiceImpl implements RequestService { @Override @Transactional @CacheEvict(value = {"projects", "technologies"}, key = "'all'") public Request requestClaimed(RequestClaimedCommand command) { final Request request = updateStatus(requestRepository.findByPlatformAndPlatformId(command.getPlatform(), command.getPlatformId()) .orElseThrow(ResourceNotFoundException::new), RequestStatus.CLAIMED); Claim claim = claimRepository.save(ClaimBuilder.aClaim() .withRequestId(request.getId()) .withSolver(command.getSolver()) .withTimestamp(command.getTimestamp()) .withTokenValue(TokenValue.builder() .tokenAddress(command.getTokenHash()) .amountInWei(command.getAmountInWei()) .build()) .withBlockchainEventId(command.getBlockchainEventId()) .build()); eventPublisher.publishEvent(RequestClaimedEvent.builder() .blockchainEventId(command.getBlockchainEventId()) .requestDto(mappers.map(Request.class, RequestDto.class, request)) .claimDto(mappers.map(Claim.class, ClaimDto.class, claim)) .solver(command.getSolver()) .timestamp(command.getTimestamp()) .build()); return request; } RequestServiceImpl(final RequestRepository requestRepository,
                              final Mappers mappers,
                              final GithubPlatformIdParser githubLinkParser,
                              final ProfileService profileService,
                              final ClaimRepository claimRepository,
                              final GithubGateway githubGateway,
                              final GithubClaimResolver githubClaimResolver,
                              final ApplicationEventPublisher eventPublisher,
                              final Erc67Generator erc67Generator,
                              final Environment environment); @Override @Transactional(readOnly = true) List<RequestDto> findAll(); @Transactional(readOnly = true) List<RequestDto> findAllFor(final List<String> projects, final List<String> technologies, final Long lastUpdatedSinceDays); @Override @Transactional(readOnly = true) List<RequestDto> findAll(Iterable<Long> ids); @Override @Transactional(readOnly = true) @Cacheable(value = "technologies", key = "'all'") Set<String> findAllTechnologies(); @Override @Transactional(readOnly = true) @Cacheable(value = "projects", key = "'all'") Set<String> findAllProjects(); @Override @Transactional UserClaimableDto getUserClaimableResult(final Principal principal, final Long requestId); @Override @Transactional ClaimableResultDto getClaimableResult(final Long requestId); @Override @Transactional(readOnly = true) List<RequestDto> findRequestsForUser(Principal principal); @Override @Transactional(readOnly = true) RequestDto findRequest(Long id); @Override @Transactional(readOnly = true) List<CommentDto> getComments(Long requestId); @Override @Transactional(readOnly = true) RequestDto findRequest(Platform platform, String platformId); @Override @Transactional @CacheEvict(value = {"projects", "technologies"}, key = "'all'") Long createRequest(CreateRequestCommand command); @Override @Transactional @CacheEvict(value = {"projects", "technologies"}, key = "'all'") Request requestClaimed(RequestClaimedCommand command); @Override @Transactional(readOnly = true) SignedClaim signClaimRequest(Principal user, UserClaimRequest userClaimRequest); @Override @Transactional(readOnly = true) Boolean canClaim(Principal user, CanClaimRequest canClaimRequest); @Override @Transactional void addWatcherToRequest(Principal principal, Long requestId); @Override @Transactional void removeWatcherFromRequest(Principal principal, Long requestId); @Override String generateERC67(final CreateERC67FundRequest createERC67FundRequest); @Override void update(final UpdateRequestStatusCommand command); }
RequestServiceImpl implements RequestService { @Override @Transactional @CacheEvict(value = {"projects", "technologies"}, key = "'all'") public Request requestClaimed(RequestClaimedCommand command) { final Request request = updateStatus(requestRepository.findByPlatformAndPlatformId(command.getPlatform(), command.getPlatformId()) .orElseThrow(ResourceNotFoundException::new), RequestStatus.CLAIMED); Claim claim = claimRepository.save(ClaimBuilder.aClaim() .withRequestId(request.getId()) .withSolver(command.getSolver()) .withTimestamp(command.getTimestamp()) .withTokenValue(TokenValue.builder() .tokenAddress(command.getTokenHash()) .amountInWei(command.getAmountInWei()) .build()) .withBlockchainEventId(command.getBlockchainEventId()) .build()); eventPublisher.publishEvent(RequestClaimedEvent.builder() .blockchainEventId(command.getBlockchainEventId()) .requestDto(mappers.map(Request.class, RequestDto.class, request)) .claimDto(mappers.map(Claim.class, ClaimDto.class, claim)) .solver(command.getSolver()) .timestamp(command.getTimestamp()) .build()); return request; } RequestServiceImpl(final RequestRepository requestRepository,
                              final Mappers mappers,
                              final GithubPlatformIdParser githubLinkParser,
                              final ProfileService profileService,
                              final ClaimRepository claimRepository,
                              final GithubGateway githubGateway,
                              final GithubClaimResolver githubClaimResolver,
                              final ApplicationEventPublisher eventPublisher,
                              final Erc67Generator erc67Generator,
                              final Environment environment); @Override @Transactional(readOnly = true) List<RequestDto> findAll(); @Transactional(readOnly = true) List<RequestDto> findAllFor(final List<String> projects, final List<String> technologies, final Long lastUpdatedSinceDays); @Override @Transactional(readOnly = true) List<RequestDto> findAll(Iterable<Long> ids); @Override @Transactional(readOnly = true) @Cacheable(value = "technologies", key = "'all'") Set<String> findAllTechnologies(); @Override @Transactional(readOnly = true) @Cacheable(value = "projects", key = "'all'") Set<String> findAllProjects(); @Override @Transactional UserClaimableDto getUserClaimableResult(final Principal principal, final Long requestId); @Override @Transactional ClaimableResultDto getClaimableResult(final Long requestId); @Override @Transactional(readOnly = true) List<RequestDto> findRequestsForUser(Principal principal); @Override @Transactional(readOnly = true) RequestDto findRequest(Long id); @Override @Transactional(readOnly = true) List<CommentDto> getComments(Long requestId); @Override @Transactional(readOnly = true) RequestDto findRequest(Platform platform, String platformId); @Override @Transactional @CacheEvict(value = {"projects", "technologies"}, key = "'all'") Long createRequest(CreateRequestCommand command); @Override @Transactional @CacheEvict(value = {"projects", "technologies"}, key = "'all'") Request requestClaimed(RequestClaimedCommand command); @Override @Transactional(readOnly = true) SignedClaim signClaimRequest(Principal user, UserClaimRequest userClaimRequest); @Override @Transactional(readOnly = true) Boolean canClaim(Principal user, CanClaimRequest canClaimRequest); @Override @Transactional void addWatcherToRequest(Principal principal, Long requestId); @Override @Transactional void removeWatcherFromRequest(Principal principal, Long requestId); @Override String generateERC67(final CreateERC67FundRequest createERC67FundRequest); @Override void update(final UpdateRequestStatusCommand command);  }