@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 testSetNonexistentInvestorComplete() throws Exception { KycInfo testKycInfo = createKycInfo(true, 0, false); when(mockKycInfoService.getKycInfoByInvestorId(INVESTOR_ID)).thenThrow(new InvestorNotFoundException()); MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(KYC_INVESTOR_COMPLETE) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isBadRequest()) .andDo(print()) .andReturn(); verify(mockKycInfoService, never()).setKycComplete(testKycInfo.getInvestorId(), true); assertThat(result.getResponse().getErrorMessage()).isEqualTo(NONEXISTENT_INVESTOR_REASON); }
@Test public void testKycReminder_nonexistentInvestor() throws Exception { when(mockKycInfoService.getKycInfoByInvestorId(INVESTOR_ID)).thenThrow(new InvestorNotFoundException()); MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(KYC_REMIND)) .andExpect(status().isBadRequest()) .andDo(print()) .andReturn(); assertThat(result.getResponse().getErrorMessage()).isEqualTo(NONEXISTENT_INVESTOR_REASON); }
@Test public void testStartKycWithMalformedUri() throws Exception { KycStartRequestDTO requestWithMalformedUri = new KycStartRequestDTO("this is not a url"); when(mockKycInfoService.getKycInfoByInvestorId(INVESTOR_ID)).thenThrow(new InvestorNotFoundException()); MvcResult result = mockMvc.perform(MockMvcRequestBuilders.post(KYC_INVESTOR_START) .contentType(MediaType.APPLICATION_JSON) .content(mapper.writeValueAsString(requestWithMalformedUri))) .andExpect(status().isBadRequest()) .andDo(print()) .andReturn(); assertThat(result.getResponse().getErrorMessage()).isEqualTo(KYC_LINK_REASON); }
@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)); }
@Test public void testGetKycStatus() throws Exception { KycInfo kycInfo = createKycInfo(true, 0,true); when(mockKycInfoService.getKycInfoByInvestorId(INVESTOR_ID)).thenReturn(kycInfo); MvcResult result1 = mockMvc.perform(MockMvcRequestBuilders.get(KYC_INVESTOR_STATUS) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andDo(print()) .andReturn(); KycInfo actual = mapper.readValue(result1.getResponse().getContentAsString(), KycInfo.class); assertThat(kycInfo.equals(actual)); when(mockKycInfoService.getKycInfoByInvestorId(INVESTOR_ID)).thenThrow(new InvestorNotFoundException()); MvcResult result2 = mockMvc.perform(MockMvcRequestBuilders.get(KYC_INVESTOR_STATUS) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isBadRequest()) .andDo(print()) .andReturn(); assertThat(result2.getResponse().getErrorMessage()).isEqualTo(NONEXISTENT_INVESTOR_REASON); }