@Test public void shouldFailOnMissingCardTypeCode() { updatePaymentDetails("Bo Nielsen", new CardTypeWsDTO(), "ksdjhfskdfhsdkhfsdkfhsdkf", null, null, "01", "2016"); testObj.validate(paymentDetailsWsDTO, errors); Assert.assertEquals("Only errors is expected", 1, errors.getErrorCount()); String[] codes = errors.getAllErrors().get(0).getCodes(); Assert.assertTrue("The first code is expected to contain cardType.code", codes[0].contains("cardType.code")); }
@Override public void validate(final Object target, final Errors errors) { final PaymentDetailsWsDTO paymentDetails = (PaymentDetailsWsDTO) target; if (StringUtils.isNotBlank(paymentDetails.getStartMonth()) && StringUtils.isNotBlank(paymentDetails.getStartYear()) && StringUtils.isNotBlank(paymentDetails.getExpiryMonth()) && StringUtils.isNotBlank(paymentDetails.getExpiryYear())) { final Calendar start = Calendar.getInstance(); start.set(Calendar.DAY_OF_MONTH, 0); start.set(Calendar.MONTH, Integer.parseInt(paymentDetails.getStartMonth()) - 1); start.set(Calendar.YEAR, Integer.parseInt(paymentDetails.getStartYear()) - 1); final Calendar expiration = Calendar.getInstance(); expiration.set(Calendar.DAY_OF_MONTH, 0); expiration.set(Calendar.MONTH, Integer.parseInt(paymentDetails.getExpiryMonth()) - 1); expiration.set(Calendar.YEAR, Integer.parseInt(paymentDetails.getExpiryYear()) - 1); if (start.after(expiration)) { errors.rejectValue("startMonth", "payment.startDate.invalid"); } } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "accountHolderName", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cardType.code", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cseToken", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryMonth", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryYear", FIELD_REQUIRED_MESSAGE_ID); paymentAddressValidator.validate(paymentDetails, errors); }
PaymentDetailsDTOValidator implements Validator { @Override public void validate(final Object target, final Errors errors) { final PaymentDetailsWsDTO paymentDetails = (PaymentDetailsWsDTO) target; if (StringUtils.isNotBlank(paymentDetails.getStartMonth()) && StringUtils.isNotBlank(paymentDetails.getStartYear()) && StringUtils.isNotBlank(paymentDetails.getExpiryMonth()) && StringUtils.isNotBlank(paymentDetails.getExpiryYear())) { final Calendar start = Calendar.getInstance(); start.set(Calendar.DAY_OF_MONTH, 0); start.set(Calendar.MONTH, Integer.parseInt(paymentDetails.getStartMonth()) - 1); start.set(Calendar.YEAR, Integer.parseInt(paymentDetails.getStartYear()) - 1); final Calendar expiration = Calendar.getInstance(); expiration.set(Calendar.DAY_OF_MONTH, 0); expiration.set(Calendar.MONTH, Integer.parseInt(paymentDetails.getExpiryMonth()) - 1); expiration.set(Calendar.YEAR, Integer.parseInt(paymentDetails.getExpiryYear()) - 1); if (start.after(expiration)) { errors.rejectValue("startMonth", "payment.startDate.invalid"); } } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "accountHolderName", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cardType.code", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cseToken", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryMonth", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryYear", FIELD_REQUIRED_MESSAGE_ID); paymentAddressValidator.validate(paymentDetails, errors); } }
PaymentDetailsDTOValidator implements Validator { @Override public void validate(final Object target, final Errors errors) { final PaymentDetailsWsDTO paymentDetails = (PaymentDetailsWsDTO) target; if (StringUtils.isNotBlank(paymentDetails.getStartMonth()) && StringUtils.isNotBlank(paymentDetails.getStartYear()) && StringUtils.isNotBlank(paymentDetails.getExpiryMonth()) && StringUtils.isNotBlank(paymentDetails.getExpiryYear())) { final Calendar start = Calendar.getInstance(); start.set(Calendar.DAY_OF_MONTH, 0); start.set(Calendar.MONTH, Integer.parseInt(paymentDetails.getStartMonth()) - 1); start.set(Calendar.YEAR, Integer.parseInt(paymentDetails.getStartYear()) - 1); final Calendar expiration = Calendar.getInstance(); expiration.set(Calendar.DAY_OF_MONTH, 0); expiration.set(Calendar.MONTH, Integer.parseInt(paymentDetails.getExpiryMonth()) - 1); expiration.set(Calendar.YEAR, Integer.parseInt(paymentDetails.getExpiryYear()) - 1); if (start.after(expiration)) { errors.rejectValue("startMonth", "payment.startDate.invalid"); } } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "accountHolderName", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cardType.code", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cseToken", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryMonth", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryYear", FIELD_REQUIRED_MESSAGE_ID); paymentAddressValidator.validate(paymentDetails, errors); }  }
PaymentDetailsDTOValidator implements Validator { @Override public void validate(final Object target, final Errors errors) { final PaymentDetailsWsDTO paymentDetails = (PaymentDetailsWsDTO) target; if (StringUtils.isNotBlank(paymentDetails.getStartMonth()) && StringUtils.isNotBlank(paymentDetails.getStartYear()) && StringUtils.isNotBlank(paymentDetails.getExpiryMonth()) && StringUtils.isNotBlank(paymentDetails.getExpiryYear())) { final Calendar start = Calendar.getInstance(); start.set(Calendar.DAY_OF_MONTH, 0); start.set(Calendar.MONTH, Integer.parseInt(paymentDetails.getStartMonth()) - 1); start.set(Calendar.YEAR, Integer.parseInt(paymentDetails.getStartYear()) - 1); final Calendar expiration = Calendar.getInstance(); expiration.set(Calendar.DAY_OF_MONTH, 0); expiration.set(Calendar.MONTH, Integer.parseInt(paymentDetails.getExpiryMonth()) - 1); expiration.set(Calendar.YEAR, Integer.parseInt(paymentDetails.getExpiryYear()) - 1); if (start.after(expiration)) { errors.rejectValue("startMonth", "payment.startDate.invalid"); } } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "accountHolderName", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cardType.code", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cseToken", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryMonth", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryYear", FIELD_REQUIRED_MESSAGE_ID); paymentAddressValidator.validate(paymentDetails, errors); }  @SuppressWarnings("squid:S3740") @Override boolean supports(final Class clazz); @Override void validate(final Object target, final Errors errors); @Required void setPaymentAddressValidator(final Validator paymentAddressValidator); }
PaymentDetailsDTOValidator implements Validator { @Override public void validate(final Object target, final Errors errors) { final PaymentDetailsWsDTO paymentDetails = (PaymentDetailsWsDTO) target; if (StringUtils.isNotBlank(paymentDetails.getStartMonth()) && StringUtils.isNotBlank(paymentDetails.getStartYear()) && StringUtils.isNotBlank(paymentDetails.getExpiryMonth()) && StringUtils.isNotBlank(paymentDetails.getExpiryYear())) { final Calendar start = Calendar.getInstance(); start.set(Calendar.DAY_OF_MONTH, 0); start.set(Calendar.MONTH, Integer.parseInt(paymentDetails.getStartMonth()) - 1); start.set(Calendar.YEAR, Integer.parseInt(paymentDetails.getStartYear()) - 1); final Calendar expiration = Calendar.getInstance(); expiration.set(Calendar.DAY_OF_MONTH, 0); expiration.set(Calendar.MONTH, Integer.parseInt(paymentDetails.getExpiryMonth()) - 1); expiration.set(Calendar.YEAR, Integer.parseInt(paymentDetails.getExpiryYear()) - 1); if (start.after(expiration)) { errors.rejectValue("startMonth", "payment.startDate.invalid"); } } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "accountHolderName", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cardType.code", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "cseToken", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryMonth", FIELD_REQUIRED_MESSAGE_ID); ValidationUtils.rejectIfEmptyOrWhitespace(errors, "expiryYear", FIELD_REQUIRED_MESSAGE_ID); paymentAddressValidator.validate(paymentDetails, errors); }  @SuppressWarnings("squid:S3740") @Override boolean supports(final Class clazz); @Override void validate(final Object target, final Errors errors); @Required void setPaymentAddressValidator(final Validator paymentAddressValidator);  }