@Test public void testUrlNull() { assertTrue(underTest.isValid(null, constraintValidatorContext)); verify(constraintValidatorContext, times(0)).buildConstraintViolationWithTemplate(anyString()); }
@Override public boolean isValid(String value, ConstraintValidatorContext context) { LOGGER.info("content size validation was called. Value: {}", value); if (value == null) { return true; } else if (!value.startsWith("http")) { context.buildConstraintViolationWithTemplate(INVALID_URL_MSG).addConstraintViolation(); return false; } try { Pair<StatusType, Integer> contentLength = httpHelper.getContentLength(value); if (!contentLength.getKey().getFamily().equals(Family.SUCCESSFUL)) { String msg = String.format(FAILED_TO_GET_BY_FAMILY_TYPE, value, contentLength.getKey().getReasonPhrase()); context.buildConstraintViolationWithTemplate(msg).addConstraintViolation(); return false; } return contentLength.getValue() > 0 && contentLength.getValue() <= MAX_IN_BYTES; } catch (Throwable throwable) { LOGGER.info("content size validation failed.", throwable); context.buildConstraintViolationWithTemplate(FAILED_TO_GET_WITH_EXCEPTION).addConstraintViolation(); } return false; }
HttpContentSizeValidator implements ConstraintValidator<ValidHttpContentSize, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { LOGGER.info("content size validation was called. Value: {}", value); if (value == null) { return true; } else if (!value.startsWith("http")) { context.buildConstraintViolationWithTemplate(INVALID_URL_MSG).addConstraintViolation(); return false; } try { Pair<StatusType, Integer> contentLength = httpHelper.getContentLength(value); if (!contentLength.getKey().getFamily().equals(Family.SUCCESSFUL)) { String msg = String.format(FAILED_TO_GET_BY_FAMILY_TYPE, value, contentLength.getKey().getReasonPhrase()); context.buildConstraintViolationWithTemplate(msg).addConstraintViolation(); return false; } return contentLength.getValue() > 0 && contentLength.getValue() <= MAX_IN_BYTES; } catch (Throwable throwable) { LOGGER.info("content size validation failed.", throwable); context.buildConstraintViolationWithTemplate(FAILED_TO_GET_WITH_EXCEPTION).addConstraintViolation(); } return false; } }
HttpContentSizeValidator implements ConstraintValidator<ValidHttpContentSize, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { LOGGER.info("content size validation was called. Value: {}", value); if (value == null) { return true; } else if (!value.startsWith("http")) { context.buildConstraintViolationWithTemplate(INVALID_URL_MSG).addConstraintViolation(); return false; } try { Pair<StatusType, Integer> contentLength = httpHelper.getContentLength(value); if (!contentLength.getKey().getFamily().equals(Family.SUCCESSFUL)) { String msg = String.format(FAILED_TO_GET_BY_FAMILY_TYPE, value, contentLength.getKey().getReasonPhrase()); context.buildConstraintViolationWithTemplate(msg).addConstraintViolation(); return false; } return contentLength.getValue() > 0 && contentLength.getValue() <= MAX_IN_BYTES; } catch (Throwable throwable) { LOGGER.info("content size validation failed.", throwable); context.buildConstraintViolationWithTemplate(FAILED_TO_GET_WITH_EXCEPTION).addConstraintViolation(); } return false; }  }
HttpContentSizeValidator implements ConstraintValidator<ValidHttpContentSize, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { LOGGER.info("content size validation was called. Value: {}", value); if (value == null) { return true; } else if (!value.startsWith("http")) { context.buildConstraintViolationWithTemplate(INVALID_URL_MSG).addConstraintViolation(); return false; } try { Pair<StatusType, Integer> contentLength = httpHelper.getContentLength(value); if (!contentLength.getKey().getFamily().equals(Family.SUCCESSFUL)) { String msg = String.format(FAILED_TO_GET_BY_FAMILY_TYPE, value, contentLength.getKey().getReasonPhrase()); context.buildConstraintViolationWithTemplate(msg).addConstraintViolation(); return false; } return contentLength.getValue() > 0 && contentLength.getValue() <= MAX_IN_BYTES; } catch (Throwable throwable) { LOGGER.info("content size validation failed.", throwable); context.buildConstraintViolationWithTemplate(FAILED_TO_GET_WITH_EXCEPTION).addConstraintViolation(); } return false; }  @Override void initialize(ValidHttpContentSize constraintAnnotation); @Override boolean isValid(String value, ConstraintValidatorContext context); }
HttpContentSizeValidator implements ConstraintValidator<ValidHttpContentSize, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { LOGGER.info("content size validation was called. Value: {}", value); if (value == null) { return true; } else if (!value.startsWith("http")) { context.buildConstraintViolationWithTemplate(INVALID_URL_MSG).addConstraintViolation(); return false; } try { Pair<StatusType, Integer> contentLength = httpHelper.getContentLength(value); if (!contentLength.getKey().getFamily().equals(Family.SUCCESSFUL)) { String msg = String.format(FAILED_TO_GET_BY_FAMILY_TYPE, value, contentLength.getKey().getReasonPhrase()); context.buildConstraintViolationWithTemplate(msg).addConstraintViolation(); return false; } return contentLength.getValue() > 0 && contentLength.getValue() <= MAX_IN_BYTES; } catch (Throwable throwable) { LOGGER.info("content size validation failed.", throwable); context.buildConstraintViolationWithTemplate(FAILED_TO_GET_WITH_EXCEPTION).addConstraintViolation(); } return false; }  @Override void initialize(ValidHttpContentSize constraintAnnotation); @Override boolean isValid(String value, ConstraintValidatorContext context); static final int MAX_SIZE; static final int MAX_IN_BYTES; static final String FAILED_TO_GET_BY_FAMILY_TYPE; static final String INVALID_URL_MSG; static final String FAILED_TO_GET_WITH_EXCEPTION; }