@Test public void extendedBucketNameValidatorTest() throws Exception { String restriction = "extended"; String largeName = String.format("%0" + 10 + "d", 0).replace("0", "abcdefghij"); assertTrue("expected that a " + largeName.length() + "-character name would be okay", BucketNameValidatorRepo.getBucketNameValidator(restriction) .check(largeName)); largeName = String.format("%0" + 30 + "d", 0).replace("0", "abcdefghij"); assertTrue("expected that a " + largeName.length() + "-character name would not be okay", !BucketNameValidatorRepo.getBucketNameValidator(restriction).check(largeName)); String badName = "foo#bar"; assertTrue("expected that the name " + badName + " would not be okay", !BucketNameValidatorRepo.getBucketNameValidator(restriction) .check(badName)); badName = "foo bar"; assertTrue("expected that the name " + badName + " would not be okay", !BucketNameValidatorRepo.getBucketNameValidator(restriction) .check(badName)); badName = "foo@bar"; assertTrue("expected that the name " + badName + " would not be okay", !BucketNameValidatorRepo.getBucketNameValidator(restriction) .check(badName)); badName = "foo,bar"; assertTrue("expected that the name " + badName + " would not be okay", !BucketNameValidatorRepo.getBucketNameValidator(restriction) .check(badName)); }
public static Validator<String> getBucketNameValidator(final String restrictionValue) { if (restrictionValue != null && "extended".equalsIgnoreCase(restrictionValue)) { return extendedValidator; } else if (restrictionValue != null && "dns-compliant".equalsIgnoreCase(restrictionValue)) { return dnsCompliantValidator; } else { return new Validator<String>() { @Override public boolean check(String value) { LOG.error("the value " + restrictionValue + " is not valid, must be either 'extended' or 'dns-compliant'. No validation " + "will be done on the specified bucket name (may result in errors)."); if (value != null && value.length() > 0) { return true; } return false; } }; } }
BucketNameValidatorRepo { public static Validator<String> getBucketNameValidator(final String restrictionValue) { if (restrictionValue != null && "extended".equalsIgnoreCase(restrictionValue)) { return extendedValidator; } else if (restrictionValue != null && "dns-compliant".equalsIgnoreCase(restrictionValue)) { return dnsCompliantValidator; } else { return new Validator<String>() { @Override public boolean check(String value) { LOG.error("the value " + restrictionValue + " is not valid, must be either 'extended' or 'dns-compliant'. No validation " + "will be done on the specified bucket name (may result in errors)."); if (value != null && value.length() > 0) { return true; } return false; } }; } } }
BucketNameValidatorRepo { public static Validator<String> getBucketNameValidator(final String restrictionValue) { if (restrictionValue != null && "extended".equalsIgnoreCase(restrictionValue)) { return extendedValidator; } else if (restrictionValue != null && "dns-compliant".equalsIgnoreCase(restrictionValue)) { return dnsCompliantValidator; } else { return new Validator<String>() { @Override public boolean check(String value) { LOG.error("the value " + restrictionValue + " is not valid, must be either 'extended' or 'dns-compliant'. No validation " + "will be done on the specified bucket name (may result in errors)."); if (value != null && value.length() > 0) { return true; } return false; } }; } }  }
BucketNameValidatorRepo { public static Validator<String> getBucketNameValidator(final String restrictionValue) { if (restrictionValue != null && "extended".equalsIgnoreCase(restrictionValue)) { return extendedValidator; } else if (restrictionValue != null && "dns-compliant".equalsIgnoreCase(restrictionValue)) { return dnsCompliantValidator; } else { return new Validator<String>() { @Override public boolean check(String value) { LOG.error("the value " + restrictionValue + " is not valid, must be either 'extended' or 'dns-compliant'. No validation " + "will be done on the specified bucket name (may result in errors)."); if (value != null && value.length() > 0) { return true; } return false; } }; } }  static Validator<String> getBucketNameValidator(final String restrictionValue); }
BucketNameValidatorRepo { public static Validator<String> getBucketNameValidator(final String restrictionValue) { if (restrictionValue != null && "extended".equalsIgnoreCase(restrictionValue)) { return extendedValidator; } else if (restrictionValue != null && "dns-compliant".equalsIgnoreCase(restrictionValue)) { return dnsCompliantValidator; } else { return new Validator<String>() { @Override public boolean check(String value) { LOG.error("the value " + restrictionValue + " is not valid, must be either 'extended' or 'dns-compliant'. No validation " + "will be done on the specified bucket name (may result in errors)."); if (value != null && value.length() > 0) { return true; } return false; } }; } }  static Validator<String> getBucketNameValidator(final String restrictionValue);  }