@Test @Ignore public void testShouldReturnTrueWhenOtpValidated() throws Exception { server.expect(once(), requestTo("http: .andExpect(content().string(new Resources().getFileContents("otpValidationRequest.json"))) .andRespond(withSuccess(new Resources().getFileContents("otpValidateResponse.json"), MediaType.APPLICATION_JSON_UTF8)); final OtpValidateRequest request = buildValidateRequest(); boolean isOtpValidated = otpRepository.validateOtp(request); server.verify(); assertEquals(Boolean.TRUE, isOtpValidated); }
public boolean validateOtp(OtpValidateRequest request) { try { OtpResponse otpResponse = restTemplate.postForObject(otpValidateEndpoint, request, OtpResponse.class); if(null!=otpResponse && null!=otpResponse.getOtp()) return otpResponse.getOtp().isValidationSuccessful(); else return false; }catch(HttpClientErrorException e){ log.error("Otp validation failed", e); throw new ServiceCallException(e.getResponseBodyAsString()); } }
OtpRepository { public boolean validateOtp(OtpValidateRequest request) { try { OtpResponse otpResponse = restTemplate.postForObject(otpValidateEndpoint, request, OtpResponse.class); if(null!=otpResponse && null!=otpResponse.getOtp()) return otpResponse.getOtp().isValidationSuccessful(); else return false; }catch(HttpClientErrorException e){ log.error("Otp validation failed", e); throw new ServiceCallException(e.getResponseBodyAsString()); } } }
OtpRepository { public boolean validateOtp(OtpValidateRequest request) { try { OtpResponse otpResponse = restTemplate.postForObject(otpValidateEndpoint, request, OtpResponse.class); if(null!=otpResponse && null!=otpResponse.getOtp()) return otpResponse.getOtp().isValidationSuccessful(); else return false; }catch(HttpClientErrorException e){ log.error("Otp validation failed", e); throw new ServiceCallException(e.getResponseBodyAsString()); } } @Autowired  OtpRepository(@Value("${egov.otp.host}") String otpServiceHost,
                         @Value("${egov.services.otp.search_otp}") String otpSearchContextEndpoint,
                         @Value("${egov.services.otp.validate_otp}") String otpValidateEndpoint,
                         RestTemplate restTemplate); }
OtpRepository { public boolean validateOtp(OtpValidateRequest request) { try { OtpResponse otpResponse = restTemplate.postForObject(otpValidateEndpoint, request, OtpResponse.class); if(null!=otpResponse && null!=otpResponse.getOtp()) return otpResponse.getOtp().isValidationSuccessful(); else return false; }catch(HttpClientErrorException e){ log.error("Otp validation failed", e); throw new ServiceCallException(e.getResponseBodyAsString()); } } @Autowired  OtpRepository(@Value("${egov.otp.host}") String otpServiceHost,
                         @Value("${egov.services.otp.search_otp}") String otpSearchContextEndpoint,
                         @Value("${egov.services.otp.validate_otp}") String otpValidateEndpoint,
                         RestTemplate restTemplate); boolean isOtpValidationComplete(OtpValidationRequest request); boolean validateOtp(OtpValidateRequest request); }
OtpRepository { public boolean validateOtp(OtpValidateRequest request) { try { OtpResponse otpResponse = restTemplate.postForObject(otpValidateEndpoint, request, OtpResponse.class); if(null!=otpResponse && null!=otpResponse.getOtp()) return otpResponse.getOtp().isValidationSuccessful(); else return false; }catch(HttpClientErrorException e){ log.error("Otp validation failed", e); throw new ServiceCallException(e.getResponseBodyAsString()); } } @Autowired  OtpRepository(@Value("${egov.otp.host}") String otpServiceHost,
                         @Value("${egov.services.otp.search_otp}") String otpSearchContextEndpoint,
                         @Value("${egov.services.otp.validate_otp}") String otpValidateEndpoint,
                         RestTemplate restTemplate); boolean isOtpValidationComplete(OtpValidationRequest request); boolean validateOtp(OtpValidateRequest request);  }