private RemindSingleKycResponseDTO remindKyc(long investorId, URI kycUri) throws NonexistentInvestorException { Investor investor; try { investor = investorService.getInvestorByInvestorId(investorId); KycReminderEmailMessage kycReminderEmailMessage = messageFactory.makeKycReminderEmailMessage(investor, kycUri); messageService.send(kycReminderEmailMessage); return new RemindSingleKycResponseDTO(investorId, true); } catch(InvestorNotFoundException e) { throw new NonexistentInvestorException(); } }
private StartSingleKycResponseDTO initiateKyc(long investorId, URI kycUri) throws NonexistentInvestorException, KycLinkException, UnexpectedException { Investor investor; try { investor = investorService.getInvestorByInvestorId(investorId); kycInfoService.saveKycInfo(investorId, kycUri); if(kycUri == null) { kycUri = new URI(linkCreator.getKycLink(investorId)); kycInfoService.setKycUri(investorId, kycUri.toASCIIString()); } KycStartEmailMessage kycStartEmail = messageFactory.makeKycStartEmailMessage(investor, kycUri); messageService.send(kycStartEmail); return new StartSingleKycResponseDTO(investorId, true); } catch(KycInfoNotSavedException e) { LOG.error("KYC Info not saved.", e); throw new UnexpectedException(); } catch(InvestorNotFoundException e) { throw new NonexistentInvestorException(); } catch(URISyntaxException e) { throw new KycLinkException(); } }
@Test public void testKycReminder() throws Exception { Investor investor = new Investor(new Date(), "test@test.com", "1234"); KycReminderEmailMessage message = new KycReminderEmailMessage(build(investor), KYC_LINK); KycInfo kycInfo = createKycInfo(true, 0, false); when(mockKycInfoService.getKycInfoByInvestorId(INVESTOR_ID)).thenReturn(kycInfo); when(mockInvestorService.getInvestorByInvestorId(INVESTOR_ID)).thenReturn(investor); when(mockMessageFactory.makeKycReminderEmailMessage(eq(investor), eq(new URI(KYC_LINK)))).thenReturn(message); MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(KYC_REMIND)) .andExpect(status().isOk()) .andDo(print()) .andReturn(); verify(mockMessageService, times(1)).send(any(KycReminderEmailMessage.class)); assertThat(result.getResponse().getContentAsString()).isEqualTo( jsonRemindSingleKycResponse.write(new RemindSingleKycResponseDTO(INVESTOR_ID, true)).getJson() ); }
@Test public void testStartKycWithNonexistentInvestor() throws Exception { when(mockKycInfoService.getKycInfoByInvestorId(INVESTOR_ID)).thenThrow(new InvestorNotFoundException()); when(mockInvestorService.getInvestorByInvestorId(INVESTOR_ID)).thenThrow(new InvestorNotFoundException()); MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(KYC_INVESTOR_START) .contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(kycStartRequest))) .andExpect(status().isBadRequest()) .andDo(print()) .andReturn(); verify(mockMessageService, never()).send(any(KycStartEmailMessage.class)); assertThat(result.getResponse().getErrorMessage()).isEqualTo(NONEXISTENT_INVESTOR_REASON); }
@Test public void testGetInvestorByInvestorId() { try { Investor investorFromDb = investorService.getInvestorByInvestorId(investor.getId()); assertEquals(investor, investorFromDb); } catch(InvestorNotFoundException e) { fail(e.getMessage()); } }
@Test public void testStartKycWithExistingInvestor() throws Exception { Investor investor = new Investor(new Date(), "test@test.com", "1234"); KycStartEmailMessage message = new KycStartEmailMessage(build(investor), KYC_LINK); when(mockKycInfoService.getKycInfoByInvestorId(INVESTOR_ID)).thenThrow(new InvestorNotFoundException()); when(mockInvestorService.getInvestorByInvestorId(INVESTOR_ID)).thenReturn(investor); when(mockMessageFactory.makeKycStartEmailMessage(eq(investor), eq(new URI(KYC_LINK)))).thenReturn(message); // start with link MvcResult result1 = mockMvc.perform(MockMvcRequestBuilders.post(KYC_INVESTOR_START) .contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(kycStartRequest))) .andExpect(status().isOk()) .andDo(print()) .andReturn(); assertThat(result1.getResponse().getContentAsString()).isEqualTo( jsonStartSingleKycResponse.write(new StartSingleKycResponseDTO(INVESTOR_ID, true)).getJson() ); // start without providing link when(mockLinkCreatorService.getKycLink(INVESTOR_ID)).thenReturn(KYC_LINK); MvcResult result2 = mockMvc.perform(MockMvcRequestBuilders.post(KYC_INVESTOR_START) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(print()) .andReturn(); assertThat(result2.getResponse().getContentAsString()).isEqualTo( jsonStartSingleKycResponse.write(new StartSingleKycResponseDTO(INVESTOR_ID, true)).getJson() ); verify(mockMessageService, times(2)).send(eq(message)); }