CommonConfigurationValidator implements ConfigurationValidator<AbstractConfiguration> { @Override public void validate(CacheElementOperation operation, AbstractConfiguration config) throws IllegalArgumentException { if (StringUtils.isBlank(config.getId())) { throw new IllegalArgumentException( config.getClass().getSimpleName() + " identifier is required."); } switch (operation) { case UPDATE: case CREATE: validateCreate(config); break; case DELETE: break; default: } }  @Override void validate(CacheElementOperation operation, AbstractConfiguration config);  }
@Test public void blankName() throws Exception { assertThatThrownBy(() -> validator.validate(CacheElementOperation.CREATE, config)).isInstanceOf( IllegalArgumentException.class) .hasMessageContaining( "identifier is required."); assertThatThrownBy(() -> validator.validate(CacheElementOperation.DELETE, config)).isInstanceOf( IllegalArgumentException.class) .hasMessageContaining( "identifier is required."); }
@Test public void invalidGroup_cluster() throws Exception { config.setName("test"); config.setGroup("cluster"); assertThatThrownBy(() -> validator.validate(CacheElementOperation.CREATE, config)).isInstanceOf( IllegalArgumentException.class) .hasMessageContaining( "'cluster' is a reserved group name"); }
@Test public void invalidGroup_comma() throws Exception { config.setName("test"); config.setGroup("group1,group2"); assertThatThrownBy(() -> validator.validate(CacheElementOperation.CREATE, config)).isInstanceOf( IllegalArgumentException.class) .hasMessageContaining( "Group name should not contain comma"); }