@Test public void claim() { Principal solver = PrincipalMother.davyvanroy(); UserClaimRequest userClaimRequest = UserClaimRequestMother.kazuki43zooApiStub().build(); Request request = RequestMother.freeCodeCampNoUserStories().build(); when(requestRepository.findByPlatformAndPlatformId(userClaimRequest.getPlatform(), userClaimRequest.getPlatformId())) .thenReturn(Optional.of(request)); RequestDto requestDto = RequestDtoMother.freeCodeCampNoUserStories(); when(mappers.map(Request.class, RequestDto.class, request)).thenReturn(requestDto); when(githubClaimResolver.getUserPlatformUsername(solver, request.getIssueInformation().getPlatform())) .thenReturn(Optional.of(solver.getName())); when(githubClaimResolver.canClaim(solver, requestDto)).thenReturn(true); claimService.claim(solver, userClaimRequest); assertThat(request.getStatus()).isEqualTo(RequestStatus.CLAIM_REQUESTED); verify(requestRepository).save(request); ArgumentCaptor<RequestClaim> requestClaimArgumentCaptor = ArgumentCaptor.forClass(RequestClaim.class); verify(requestClaimRepository).save(requestClaimArgumentCaptor.capture()); RequestClaim requestClaim = requestClaimArgumentCaptor.getValue(); assertThat(requestClaim.getRequestId()).isEqualTo(request.getId()); assertThat(requestClaim.getAddress()).isEqualTo(userClaimRequest.getAddress()); assertThat(requestClaim.getSolver()).isEqualTo(solver.getName()); assertThat(requestClaim.getFlagged()).isFalse(); assertThat(requestClaim.getStatus()).isEqualTo(ClaimRequestStatus.PENDING); }
@Transactional @Override public void claim(Principal user, UserClaimRequest userClaimRequest) { Request request = requestRepository.findByPlatformAndPlatformId(userClaimRequest.getPlatform(), userClaimRequest.getPlatformId()) .orElseThrow(() -> new RuntimeException("Request not found")); RequestDto requestDto = mappers.map(Request.class, RequestDto.class, request); String solver = githubClaimResolver.getUserPlatformUsername(user, request.getIssueInformation().getPlatform()) .orElseThrow(() -> new RuntimeException("You are not linked to github")); final RequestClaim requestClaim = RequestClaim.builder() .address(userClaimRequest.getAddress()) .requestId(request.getId()) .flagged(!githubClaimResolver.canClaim(user, requestDto)) .solver(solver) .status(ClaimRequestStatus.PENDING) .build(); requestClaimRepository.save(requestClaim); request.setStatus(RequestStatus.CLAIM_REQUESTED); eventPublisher.publishEvent(ClaimRequestedEvent.builder() .requestClaim(requestClaim) .build()); requestRepository.save(request); }
ClaimServiceImpl implements ClaimService { @Transactional @Override public void claim(Principal user, UserClaimRequest userClaimRequest) { Request request = requestRepository.findByPlatformAndPlatformId(userClaimRequest.getPlatform(), userClaimRequest.getPlatformId()) .orElseThrow(() -> new RuntimeException("Request not found")); RequestDto requestDto = mappers.map(Request.class, RequestDto.class, request); String solver = githubClaimResolver.getUserPlatformUsername(user, request.getIssueInformation().getPlatform()) .orElseThrow(() -> new RuntimeException("You are not linked to github")); final RequestClaim requestClaim = RequestClaim.builder() .address(userClaimRequest.getAddress()) .requestId(request.getId()) .flagged(!githubClaimResolver.canClaim(user, requestDto)) .solver(solver) .status(ClaimRequestStatus.PENDING) .build(); requestClaimRepository.save(requestClaim); request.setStatus(RequestStatus.CLAIM_REQUESTED); eventPublisher.publishEvent(ClaimRequestedEvent.builder() .requestClaim(requestClaim) .build()); requestRepository.save(request); } }
ClaimServiceImpl implements ClaimService { @Transactional @Override public void claim(Principal user, UserClaimRequest userClaimRequest) { Request request = requestRepository.findByPlatformAndPlatformId(userClaimRequest.getPlatform(), userClaimRequest.getPlatformId()) .orElseThrow(() -> new RuntimeException("Request not found")); RequestDto requestDto = mappers.map(Request.class, RequestDto.class, request); String solver = githubClaimResolver.getUserPlatformUsername(user, request.getIssueInformation().getPlatform()) .orElseThrow(() -> new RuntimeException("You are not linked to github")); final RequestClaim requestClaim = RequestClaim.builder() .address(userClaimRequest.getAddress()) .requestId(request.getId()) .flagged(!githubClaimResolver.canClaim(user, requestDto)) .solver(solver) .status(ClaimRequestStatus.PENDING) .build(); requestClaimRepository.save(requestClaim); request.setStatus(RequestStatus.CLAIM_REQUESTED); eventPublisher.publishEvent(ClaimRequestedEvent.builder() .requestClaim(requestClaim) .build()); requestRepository.save(request); } ClaimServiceImpl(final RequestRepository requestRepository,
                            final ClaimRepository claimRepository,
                            final RequestClaimRepository requestClaimRepository,
                            final GithubClaimResolver githubClaimResolver,
                            final Mappers mappers,
                            final ClaimDtoAggregator claimDtoAggregator,
                            final ApplicationEventPublisher eventPublisher); }
ClaimServiceImpl implements ClaimService { @Transactional @Override public void claim(Principal user, UserClaimRequest userClaimRequest) { Request request = requestRepository.findByPlatformAndPlatformId(userClaimRequest.getPlatform(), userClaimRequest.getPlatformId()) .orElseThrow(() -> new RuntimeException("Request not found")); RequestDto requestDto = mappers.map(Request.class, RequestDto.class, request); String solver = githubClaimResolver.getUserPlatformUsername(user, request.getIssueInformation().getPlatform()) .orElseThrow(() -> new RuntimeException("You are not linked to github")); final RequestClaim requestClaim = RequestClaim.builder() .address(userClaimRequest.getAddress()) .requestId(request.getId()) .flagged(!githubClaimResolver.canClaim(user, requestDto)) .solver(solver) .status(ClaimRequestStatus.PENDING) .build(); requestClaimRepository.save(requestClaim); request.setStatus(RequestStatus.CLAIM_REQUESTED); eventPublisher.publishEvent(ClaimRequestedEvent.builder() .requestClaim(requestClaim) .build()); requestRepository.save(request); } ClaimServiceImpl(final RequestRepository requestRepository,
                            final ClaimRepository claimRepository,
                            final RequestClaimRepository requestClaimRepository,
                            final GithubClaimResolver githubClaimResolver,
                            final Mappers mappers,
                            final ClaimDtoAggregator claimDtoAggregator,
                            final ApplicationEventPublisher eventPublisher); @Override @Transactional(readOnly = true) Optional<ClaimDto> findOne(final Long id); @Transactional @Override void claim(Principal user, UserClaimRequest userClaimRequest); @Override @Transactional(readOnly = true) ClaimsByTransactionAggregate getAggregatedClaimsForRequest(final long requestId); @EventListener void onClaimed(final RequestClaimedEvent claimedEvent); }
ClaimServiceImpl implements ClaimService { @Transactional @Override public void claim(Principal user, UserClaimRequest userClaimRequest) { Request request = requestRepository.findByPlatformAndPlatformId(userClaimRequest.getPlatform(), userClaimRequest.getPlatformId()) .orElseThrow(() -> new RuntimeException("Request not found")); RequestDto requestDto = mappers.map(Request.class, RequestDto.class, request); String solver = githubClaimResolver.getUserPlatformUsername(user, request.getIssueInformation().getPlatform()) .orElseThrow(() -> new RuntimeException("You are not linked to github")); final RequestClaim requestClaim = RequestClaim.builder() .address(userClaimRequest.getAddress()) .requestId(request.getId()) .flagged(!githubClaimResolver.canClaim(user, requestDto)) .solver(solver) .status(ClaimRequestStatus.PENDING) .build(); requestClaimRepository.save(requestClaim); request.setStatus(RequestStatus.CLAIM_REQUESTED); eventPublisher.publishEvent(ClaimRequestedEvent.builder() .requestClaim(requestClaim) .build()); requestRepository.save(request); } ClaimServiceImpl(final RequestRepository requestRepository,
                            final ClaimRepository claimRepository,
                            final RequestClaimRepository requestClaimRepository,
                            final GithubClaimResolver githubClaimResolver,
                            final Mappers mappers,
                            final ClaimDtoAggregator claimDtoAggregator,
                            final ApplicationEventPublisher eventPublisher); @Override @Transactional(readOnly = true) Optional<ClaimDto> findOne(final Long id); @Transactional @Override void claim(Principal user, UserClaimRequest userClaimRequest); @Override @Transactional(readOnly = true) ClaimsByTransactionAggregate getAggregatedClaimsForRequest(final long requestId); @EventListener void onClaimed(final RequestClaimedEvent claimedEvent);  }