private Investor createInvestor(String email, String randomUUID, String ipAddress) { return new Investor(new Date(), email, randomUUID, ipAddress); }
private Investor createInvestor() { String randomUUID = UUID.randomUUID().toString(); return new Investor(new Date(), "test@test.com", randomUUID, "wallet-address-12345", "payInEther1", "payInBitcoin1", "refundEther1", "refundEther2", "127.0.0.1"); }
private Investor createInvestor(int i) { return investorRepository.save( new Investor(new Date(), "emailAddress" + i, "token" + i, "walletAddress", "payInEtherPublicKey" + i, "payInBitcoinPublicKey" + i, "refundEtherAddress", "refundBitcoinAddress", "ipAddress")); }
@Test(expected = DataIntegrityViolationException.class) public void testEmailConfirmationTokenUniqueConstraint() { String randomUUID = UUID.randomUUID().toString(); Investor i1 = new Investor(new Date(), "test1@test1.com", randomUUID); investorRepository.saveAndFlush(i1); Investor i2 = new Investor(new Date(), "test2@test2.com", randomUUID); investorRepository.saveAndFlush(i2); }
@Test(expected = DataIntegrityViolationException.class) public void testEmailUniqueConstraint() { Investor i1 = new Investor(new Date(), "test@test.com", UUID.randomUUID().toString()); investorRepository.saveAndFlush(i1); Investor i2 = new Investor(new Date(), "test@test.com", UUID.randomUUID().toString()); investorRepository.saveAndFlush(i2); }
@Before public void setUp() { investor = new Investor(new Date(), "test@test.com", "1234"); investorRepository.save(investor); }
@Test public void testSave() { Investor i = new Investor(new Date(), "test@test.com", "somelongtoken" ); investorRepository.save(i); }
private Investor buildInvestor(ECKey key) { return new Investor( new Date(), "email@email.com", "emailConfirmationToken", "walletAddress", TypeConverter.toJsonHex(key.getAddress()), "payInBitcoinAddress", "refundEtherAddress", "refundBitcoinAddress", "127.0.0.1" ); }
private Investor createInvestor() { try { return investorService.getInvestorByEmail(INVESTOR_EMAIL); } catch (InvestorNotFoundException e) { return investorService.saveTransactionless( new Investor(new java.util.Date(), INVESTOR_EMAIL, "token", "walletAddress", "payInEtherPublicKey", "payInBitcoinPublicKey", "refundEtherAddress", "refundBitcoinAddress", "ipAddress")); } }
@Test public void testFindByEmailConfirmationToken() { String randomUUID = UUID.randomUUID().toString(); Investor i = new Investor(new Date(), "test@test.com", randomUUID); investorRepository.save(i); Optional<Investor> oInvestor = investorRepository.findOptionalByEmailConfirmationToken(randomUUID); assertTrue(oInvestor.isPresent()); assertTrue(oInvestor.get().getEmailConfirmationToken().equals(randomUUID)); }
@Test public void testStartKycForAll() throws Exception { List<Investor> investorList = new ArrayList<>(); List<Long> kycStartedList = new ArrayList<>(); Investor investor1 = new Investor(new Date(), "investor1@test.com", "investor1token").setId(1); Investor investor2 = new Investor(new Date(), "investor2@test.com", "investor2token").setId(2); Investor investor3 = new Investor(new Date(), "investor3@test.com", "investor3token").setId(3); Investor investor4 = new Investor(new Date(), "investor4@test.com", "investor4token").setId(4); investorList.add(investor1); investorList.add(investor2); investorList.add(investor3); investorList.add(investor4); kycStartedList.add(2L); when(mockInvestorService.getAllInvestors()).thenReturn(investorList); when(mockKycInfoService.getAllInvestorIdWhereStartKycEmailSent()).thenReturn(kycStartedList); when(mockLinkCreatorService.getKycLink(anyLong())).thenReturn(KYC_LINK); when(mockPaymentLogService.hasInvestorInvested(1)).thenReturn(true); when(mockPaymentLogService.hasInvestorInvested(3)).thenReturn(false); when(mockPaymentLogService.hasInvestorInvested(4)).thenReturn(true); MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(KYC_START_ALL) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(print()) .andReturn(); StartAllKycResponseDTO responseDTO = mapper.readValue(result.getResponse().getContentAsString(), StartAllKycResponseDTO.class); assertThat(responseDTO.getKycStartedList()).containsExactly(1L, 4L); assertThat(responseDTO.getErrorList()).isEmpty(); }
@RabbitListener( bindings = @QueueBinding(value = @Queue(value = REGISTER_CONFIRMATION_EMAIL_QUEUE, autoDelete = "false"), exchange = @Exchange( value = ICONATOR_ENTRY_EXCHANGE, type = ExchangeTypes.TOPIC, ignoreDeclarationExceptions = "true", durable = "true" ), key = REGISTER_CONFIRMATION_EMAIL_ROUTING_KEY) ) public void receiveMessage(ConfirmationEmailMessage messageObject) { try { // TODO: 05.03.18 Guil: // Add a retry mechanism (e.g., for when the SMTP server is offline) mailService.sendConfirmationEmail( new Investor().setEmail(messageObject.getInvestor().getEmail()), messageObject.getEmailLinkUri() ); } catch (Exception e) { // TODO: 05.03.18 Guil: // Instead of just output the error, send to a structured log, // e.g., logstash or, also, send an email to an admin LOG.error("Email not sent.", e); } }
@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() ); }
public Investor toInvestor() { return new Investor( getCreationDate(), getEmail(), getEmailConfirmationToken(), getWalletAddress(), getPayInEtherAddress(), getPayInBitcoinAddress(), getRefundEtherAddress(), getRefundBitcoinAddress(), getIpAddress() ); }
@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)); }
Investor investor = new Investor(new Date(), "test@test.com", "1234"); KycInfo testKycInfo2 = createKycInfo(true, 0,false); KycReminderEmailMessage message = new KycReminderEmailMessage(build(investor), KYC_LINK);