NameValidationUtils { private static void validate(String ownerKey, String name, String regex, String message) { if (!isValid(name, regex)) { if (log.isDebugEnabled()) { log.debug("{}: invalid name [ {} ]. Expects one matching the regex [ {} ]", ownerKey, name, regex); } throw new InvalidNameException(ownerKey, name, message); } }  static boolean isValid(String name); static void validate(String ownerKey, String name); static void validateApplicationName(String name); static void validateApplicationId(String id); static void validateNodeName(String name); static final String DEFAULT_NAME_REGEX; static final Pattern DEFAULT_NAME_REPLACE_PATTERN; static final String APPLICATION_NAME_REGEX; static final String NODE_NAME_REGEX; }
@Test public void validateDefaultTest() { NameValidationUtils.validate("owner", "Compute"); NameValidationUtils.validate("owner", "Compute_2"); List<String> invalids = Lists.newArrayList("Computé", "Compute-2", "Compute.unix", "Compute 2"); invalids.forEach(invalid -> { expectException(new Callable() { @Override public Object call() throws Exception { NameValidationUtils.validate("owner", invalid); return null; } }, InvalidNameException.class); }); }