@Test public void testValidate_name() { validate(new OrientRoutingRule(null, "desc", RoutingMode.BLOCK, Collections.singletonList(".*")), "name", "A non-empty value must be specified"); validate(new OrientRoutingRule("\t", "desc", RoutingMode.BLOCK, Collections.singletonList(".*")), "name", "A non-empty value must be specified"); validate(new OrientRoutingRule("asdf asdf", "desc", RoutingMode.BLOCK, Collections.singletonList(".*")), "name", "Only letters, digits, underscores(_), hyphens(-), and dots(.) are allowed and may not start with underscore or dot."); }
@VisibleForTesting static void validate(final RoutingRule rule) { ValidationErrorsException exception = new ValidationErrorsException(); if (Strings2.isBlank(rule.name())) { exception.withError("name", "A non-empty value must be specified"); } else if (!rule.name().matches(NamePatternConstants.REGEX)) { exception.withError("name", "Only letters, digits, underscores(_), hyphens(-), and dots(.) are allowed and may not start with underscore or dot."); } else if (rule.name().equalsIgnoreCase(NONE)) { exception.withError("name", "Rule must not be named None"); } if (rule.description() == null) { exception.withError("description", "A non-null value must be specified"); } if (rule.mode() == null) { exception.withError("mode", "A non-empty value must be specified"); } if (rule.matchers() == null || rule.matchers().isEmpty()) { exception.withError("matchers", "At least one rule must be specified"); } else { int index = 0; for (String regex : rule.matchers()) { if (Strings2.isBlank(regex)) { exception.withError("matchers[" + index + "]", "Empty matchers are not allowed"); } else { try { Pattern.compile(regex); } catch (PatternSyntaxException e) { exception.withError("matchers[" + index + "]", "Invalid regex: " + e.getMessage()); } } index++; } } if (!exception.getValidationErrors().isEmpty()) { throw exception; } }
OrientRoutingRuleStore extends StateGuardLifecycleSupport implements RoutingRuleStore { @VisibleForTesting static void validate(final RoutingRule rule) { ValidationErrorsException exception = new ValidationErrorsException(); if (Strings2.isBlank(rule.name())) { exception.withError("name", "A non-empty value must be specified"); } else if (!rule.name().matches(NamePatternConstants.REGEX)) { exception.withError("name", "Only letters, digits, underscores(_), hyphens(-), and dots(.) are allowed and may not start with underscore or dot."); } else if (rule.name().equalsIgnoreCase(NONE)) { exception.withError("name", "Rule must not be named None"); } if (rule.description() == null) { exception.withError("description", "A non-null value must be specified"); } if (rule.mode() == null) { exception.withError("mode", "A non-empty value must be specified"); } if (rule.matchers() == null || rule.matchers().isEmpty()) { exception.withError("matchers", "At least one rule must be specified"); } else { int index = 0; for (String regex : rule.matchers()) { if (Strings2.isBlank(regex)) { exception.withError("matchers[" + index + "]", "Empty matchers are not allowed"); } else { try { Pattern.compile(regex); } catch (PatternSyntaxException e) { exception.withError("matchers[" + index + "]", "Invalid regex: " + e.getMessage()); } } index++; } } if (!exception.getValidationErrors().isEmpty()) { throw exception; } } }
OrientRoutingRuleStore extends StateGuardLifecycleSupport implements RoutingRuleStore { @VisibleForTesting static void validate(final RoutingRule rule) { ValidationErrorsException exception = new ValidationErrorsException(); if (Strings2.isBlank(rule.name())) { exception.withError("name", "A non-empty value must be specified"); } else if (!rule.name().matches(NamePatternConstants.REGEX)) { exception.withError("name", "Only letters, digits, underscores(_), hyphens(-), and dots(.) are allowed and may not start with underscore or dot."); } else if (rule.name().equalsIgnoreCase(NONE)) { exception.withError("name", "Rule must not be named None"); } if (rule.description() == null) { exception.withError("description", "A non-null value must be specified"); } if (rule.mode() == null) { exception.withError("mode", "A non-empty value must be specified"); } if (rule.matchers() == null || rule.matchers().isEmpty()) { exception.withError("matchers", "At least one rule must be specified"); } else { int index = 0; for (String regex : rule.matchers()) { if (Strings2.isBlank(regex)) { exception.withError("matchers[" + index + "]", "Empty matchers are not allowed"); } else { try { Pattern.compile(regex); } catch (PatternSyntaxException e) { exception.withError("matchers[" + index + "]", "Invalid regex: " + e.getMessage()); } } index++; } } if (!exception.getValidationErrors().isEmpty()) { throw exception; } } @Inject  OrientRoutingRuleStore(@Named(DatabaseInstanceNames.CONFIG) final Provider<DatabaseInstance> databaseInstance,
                                final OrientRoutingRuleEntityAdapter entityAdapter); }
OrientRoutingRuleStore extends StateGuardLifecycleSupport implements RoutingRuleStore { @VisibleForTesting static void validate(final RoutingRule rule) { ValidationErrorsException exception = new ValidationErrorsException(); if (Strings2.isBlank(rule.name())) { exception.withError("name", "A non-empty value must be specified"); } else if (!rule.name().matches(NamePatternConstants.REGEX)) { exception.withError("name", "Only letters, digits, underscores(_), hyphens(-), and dots(.) are allowed and may not start with underscore or dot."); } else if (rule.name().equalsIgnoreCase(NONE)) { exception.withError("name", "Rule must not be named None"); } if (rule.description() == null) { exception.withError("description", "A non-null value must be specified"); } if (rule.mode() == null) { exception.withError("mode", "A non-empty value must be specified"); } if (rule.matchers() == null || rule.matchers().isEmpty()) { exception.withError("matchers", "At least one rule must be specified"); } else { int index = 0; for (String regex : rule.matchers()) { if (Strings2.isBlank(regex)) { exception.withError("matchers[" + index + "]", "Empty matchers are not allowed"); } else { try { Pattern.compile(regex); } catch (PatternSyntaxException e) { exception.withError("matchers[" + index + "]", "Invalid regex: " + e.getMessage()); } } index++; } } if (!exception.getValidationErrors().isEmpty()) { throw exception; } } @Inject  OrientRoutingRuleStore(@Named(DatabaseInstanceNames.CONFIG) final Provider<DatabaseInstance> databaseInstance,
                                final OrientRoutingRuleEntityAdapter entityAdapter); @Override @Guarded(by = STARTED) RoutingRule create(final RoutingRule rule); @Override @Guarded(by = STARTED) void update(final RoutingRule rule); @Override @Guarded(by = STARTED) List<RoutingRule> list(); @Override void delete(final RoutingRule rule); @Override RoutingRule getByName(final String name); @Override RoutingRule getById(final String id); @Override RoutingRule newRoutingRule(); }
OrientRoutingRuleStore extends StateGuardLifecycleSupport implements RoutingRuleStore { @VisibleForTesting static void validate(final RoutingRule rule) { ValidationErrorsException exception = new ValidationErrorsException(); if (Strings2.isBlank(rule.name())) { exception.withError("name", "A non-empty value must be specified"); } else if (!rule.name().matches(NamePatternConstants.REGEX)) { exception.withError("name", "Only letters, digits, underscores(_), hyphens(-), and dots(.) are allowed and may not start with underscore or dot."); } else if (rule.name().equalsIgnoreCase(NONE)) { exception.withError("name", "Rule must not be named None"); } if (rule.description() == null) { exception.withError("description", "A non-null value must be specified"); } if (rule.mode() == null) { exception.withError("mode", "A non-empty value must be specified"); } if (rule.matchers() == null || rule.matchers().isEmpty()) { exception.withError("matchers", "At least one rule must be specified"); } else { int index = 0; for (String regex : rule.matchers()) { if (Strings2.isBlank(regex)) { exception.withError("matchers[" + index + "]", "Empty matchers are not allowed"); } else { try { Pattern.compile(regex); } catch (PatternSyntaxException e) { exception.withError("matchers[" + index + "]", "Invalid regex: " + e.getMessage()); } } index++; } } if (!exception.getValidationErrors().isEmpty()) { throw exception; } } @Inject  OrientRoutingRuleStore(@Named(DatabaseInstanceNames.CONFIG) final Provider<DatabaseInstance> databaseInstance,
                                final OrientRoutingRuleEntityAdapter entityAdapter); @Override @Guarded(by = STARTED) RoutingRule create(final RoutingRule rule); @Override @Guarded(by = STARTED) void update(final RoutingRule rule); @Override @Guarded(by = STARTED) List<RoutingRule> list(); @Override void delete(final RoutingRule rule); @Override RoutingRule getByName(final String name); @Override RoutingRule getById(final String id); @Override RoutingRule newRoutingRule();  }