@Test public void shouldRecognizeDuplicateIndexerNames() { IndexerConfig indexerConfigMock = mock(IndexerConfig.class); when(indexerConfigMock.getName()).thenReturn("name"); IndexerConfig indexerConfigMock2 = mock(IndexerConfig.class); when(indexerConfigMock2.getName()).thenReturn("name"); when(indexerConfigMock.validateConfig(any(), any(), any())).thenReturn(new ValidatingConfig.ConfigValidationResult(true, false, new ArrayList<String>(), new ArrayList<String>())); when(indexerConfigMock2.validateConfig(any(), any(), any())).thenReturn(new ValidatingConfig.ConfigValidationResult(true, false, new ArrayList<String>(), new ArrayList<String>())); testee.getIndexers().add(indexerConfigMock); testee.getIndexers().add(indexerConfigMock2); ValidatingConfig.ConfigValidationResult result = testee.validateConfig(new BaseConfig(), testee, new BaseConfig()); assertEquals(3, result.getErrorMessages().size()); assertTrue(result.getErrorMessages().get(2).contains("Duplicate")); }
@Override public ConfigValidationResult validateConfig(BaseConfig oldConfig, BaseConfig newConfig, BaseConfig newBaseConfig) { ConfigValidationResult configValidationResult = new ConfigValidationResult(); ConfigValidationResult authValidation = newConfig.getAuth().validateConfig(oldConfig, newConfig.getAuth(), newBaseConfig); configValidationResult.getErrorMessages().addAll(authValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(authValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || authValidation.isRestartNeeded()); ConfigValidationResult categoriesValidation = newConfig.getCategoriesConfig().validateConfig(oldConfig, newConfig.getCategoriesConfig(), newBaseConfig); configValidationResult.getErrorMessages().addAll(categoriesValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(categoriesValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || categoriesValidation.isRestartNeeded()); ConfigValidationResult mainValidation = newConfig.getMain().validateConfig(oldConfig, newConfig.getMain(), newBaseConfig); configValidationResult.getErrorMessages().addAll(mainValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(mainValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || mainValidation.isRestartNeeded()); ConfigValidationResult searchingValidation = newConfig.getSearching().validateConfig(oldConfig, newConfig.getSearching(), newBaseConfig); configValidationResult.getErrorMessages().addAll(searchingValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(searchingValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || searchingValidation.isRestartNeeded()); ConfigValidationResult downloadingValidation = newConfig.getDownloading().validateConfig(oldConfig, newConfig.getDownloading(), newBaseConfig); configValidationResult.getErrorMessages().addAll(downloadingValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(downloadingValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || downloadingValidation.isRestartNeeded()); for (IndexerConfig indexer : newConfig.getIndexers()) { ConfigValidationResult indexerValidation = indexer.validateConfig(oldConfig, indexer, newBaseConfig); configValidationResult.getErrorMessages().addAll(indexerValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(indexerValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || indexerValidation.isRestartNeeded()); } validateIndexers(newConfig, configValidationResult); if (!configValidationResult.getErrorMessages().isEmpty()) { logger.warn("Config validation returned errors:\n" + Joiner.on("\n").join(configValidationResult.getErrorMessages())); } if (!configValidationResult.getWarningMessages().isEmpty()) { logger.warn("Config validation returned warnings:\n" + Joiner.on("\n").join(configValidationResult.getWarningMessages())); } if (configValidationResult.isRestartNeeded()) { logger.warn("Settings were changed that require a restart to become effective"); } configValidationResult.setOk(configValidationResult.getErrorMessages().isEmpty()); return configValidationResult; }
BaseConfig extends ValidatingConfig<BaseConfig> { @Override public ConfigValidationResult validateConfig(BaseConfig oldConfig, BaseConfig newConfig, BaseConfig newBaseConfig) { ConfigValidationResult configValidationResult = new ConfigValidationResult(); ConfigValidationResult authValidation = newConfig.getAuth().validateConfig(oldConfig, newConfig.getAuth(), newBaseConfig); configValidationResult.getErrorMessages().addAll(authValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(authValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || authValidation.isRestartNeeded()); ConfigValidationResult categoriesValidation = newConfig.getCategoriesConfig().validateConfig(oldConfig, newConfig.getCategoriesConfig(), newBaseConfig); configValidationResult.getErrorMessages().addAll(categoriesValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(categoriesValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || categoriesValidation.isRestartNeeded()); ConfigValidationResult mainValidation = newConfig.getMain().validateConfig(oldConfig, newConfig.getMain(), newBaseConfig); configValidationResult.getErrorMessages().addAll(mainValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(mainValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || mainValidation.isRestartNeeded()); ConfigValidationResult searchingValidation = newConfig.getSearching().validateConfig(oldConfig, newConfig.getSearching(), newBaseConfig); configValidationResult.getErrorMessages().addAll(searchingValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(searchingValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || searchingValidation.isRestartNeeded()); ConfigValidationResult downloadingValidation = newConfig.getDownloading().validateConfig(oldConfig, newConfig.getDownloading(), newBaseConfig); configValidationResult.getErrorMessages().addAll(downloadingValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(downloadingValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || downloadingValidation.isRestartNeeded()); for (IndexerConfig indexer : newConfig.getIndexers()) { ConfigValidationResult indexerValidation = indexer.validateConfig(oldConfig, indexer, newBaseConfig); configValidationResult.getErrorMessages().addAll(indexerValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(indexerValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || indexerValidation.isRestartNeeded()); } validateIndexers(newConfig, configValidationResult); if (!configValidationResult.getErrorMessages().isEmpty()) { logger.warn("Config validation returned errors:\n" + Joiner.on("\n").join(configValidationResult.getErrorMessages())); } if (!configValidationResult.getWarningMessages().isEmpty()) { logger.warn("Config validation returned warnings:\n" + Joiner.on("\n").join(configValidationResult.getWarningMessages())); } if (configValidationResult.isRestartNeeded()) { logger.warn("Settings were changed that require a restart to become effective"); } configValidationResult.setOk(configValidationResult.getErrorMessages().isEmpty()); return configValidationResult; } }
BaseConfig extends ValidatingConfig<BaseConfig> { @Override public ConfigValidationResult validateConfig(BaseConfig oldConfig, BaseConfig newConfig, BaseConfig newBaseConfig) { ConfigValidationResult configValidationResult = new ConfigValidationResult(); ConfigValidationResult authValidation = newConfig.getAuth().validateConfig(oldConfig, newConfig.getAuth(), newBaseConfig); configValidationResult.getErrorMessages().addAll(authValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(authValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || authValidation.isRestartNeeded()); ConfigValidationResult categoriesValidation = newConfig.getCategoriesConfig().validateConfig(oldConfig, newConfig.getCategoriesConfig(), newBaseConfig); configValidationResult.getErrorMessages().addAll(categoriesValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(categoriesValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || categoriesValidation.isRestartNeeded()); ConfigValidationResult mainValidation = newConfig.getMain().validateConfig(oldConfig, newConfig.getMain(), newBaseConfig); configValidationResult.getErrorMessages().addAll(mainValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(mainValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || mainValidation.isRestartNeeded()); ConfigValidationResult searchingValidation = newConfig.getSearching().validateConfig(oldConfig, newConfig.getSearching(), newBaseConfig); configValidationResult.getErrorMessages().addAll(searchingValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(searchingValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || searchingValidation.isRestartNeeded()); ConfigValidationResult downloadingValidation = newConfig.getDownloading().validateConfig(oldConfig, newConfig.getDownloading(), newBaseConfig); configValidationResult.getErrorMessages().addAll(downloadingValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(downloadingValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || downloadingValidation.isRestartNeeded()); for (IndexerConfig indexer : newConfig.getIndexers()) { ConfigValidationResult indexerValidation = indexer.validateConfig(oldConfig, indexer, newBaseConfig); configValidationResult.getErrorMessages().addAll(indexerValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(indexerValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || indexerValidation.isRestartNeeded()); } validateIndexers(newConfig, configValidationResult); if (!configValidationResult.getErrorMessages().isEmpty()) { logger.warn("Config validation returned errors:\n" + Joiner.on("\n").join(configValidationResult.getErrorMessages())); } if (!configValidationResult.getWarningMessages().isEmpty()) { logger.warn("Config validation returned warnings:\n" + Joiner.on("\n").join(configValidationResult.getWarningMessages())); } if (configValidationResult.isRestartNeeded()) { logger.warn("Settings were changed that require a restart to become effective"); } configValidationResult.setOk(configValidationResult.getErrorMessages().isEmpty()); return configValidationResult; }  }
BaseConfig extends ValidatingConfig<BaseConfig> { @Override public ConfigValidationResult validateConfig(BaseConfig oldConfig, BaseConfig newConfig, BaseConfig newBaseConfig) { ConfigValidationResult configValidationResult = new ConfigValidationResult(); ConfigValidationResult authValidation = newConfig.getAuth().validateConfig(oldConfig, newConfig.getAuth(), newBaseConfig); configValidationResult.getErrorMessages().addAll(authValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(authValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || authValidation.isRestartNeeded()); ConfigValidationResult categoriesValidation = newConfig.getCategoriesConfig().validateConfig(oldConfig, newConfig.getCategoriesConfig(), newBaseConfig); configValidationResult.getErrorMessages().addAll(categoriesValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(categoriesValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || categoriesValidation.isRestartNeeded()); ConfigValidationResult mainValidation = newConfig.getMain().validateConfig(oldConfig, newConfig.getMain(), newBaseConfig); configValidationResult.getErrorMessages().addAll(mainValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(mainValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || mainValidation.isRestartNeeded()); ConfigValidationResult searchingValidation = newConfig.getSearching().validateConfig(oldConfig, newConfig.getSearching(), newBaseConfig); configValidationResult.getErrorMessages().addAll(searchingValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(searchingValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || searchingValidation.isRestartNeeded()); ConfigValidationResult downloadingValidation = newConfig.getDownloading().validateConfig(oldConfig, newConfig.getDownloading(), newBaseConfig); configValidationResult.getErrorMessages().addAll(downloadingValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(downloadingValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || downloadingValidation.isRestartNeeded()); for (IndexerConfig indexer : newConfig.getIndexers()) { ConfigValidationResult indexerValidation = indexer.validateConfig(oldConfig, indexer, newBaseConfig); configValidationResult.getErrorMessages().addAll(indexerValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(indexerValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || indexerValidation.isRestartNeeded()); } validateIndexers(newConfig, configValidationResult); if (!configValidationResult.getErrorMessages().isEmpty()) { logger.warn("Config validation returned errors:\n" + Joiner.on("\n").join(configValidationResult.getErrorMessages())); } if (!configValidationResult.getWarningMessages().isEmpty()) { logger.warn("Config validation returned warnings:\n" + Joiner.on("\n").join(configValidationResult.getWarningMessages())); } if (configValidationResult.isRestartNeeded()) { logger.warn("Settings were changed that require a restart to become effective"); } configValidationResult.setOk(configValidationResult.getErrorMessages().isEmpty()); return configValidationResult; }  void replace(BaseConfig newConfig); void save(boolean saveInstantly); @PostConstruct void init(); void load(); @EventListener void onShutdown(ShutdownEvent event); @Override ConfigValidationResult validateConfig(BaseConfig oldConfig, BaseConfig newConfig, BaseConfig newBaseConfig); @Override BaseConfig prepareForSaving(BaseConfig oldBaseConfig); @Override BaseConfig updateAfterLoading(); @Override BaseConfig initializeNewConfig(); }
BaseConfig extends ValidatingConfig<BaseConfig> { @Override public ConfigValidationResult validateConfig(BaseConfig oldConfig, BaseConfig newConfig, BaseConfig newBaseConfig) { ConfigValidationResult configValidationResult = new ConfigValidationResult(); ConfigValidationResult authValidation = newConfig.getAuth().validateConfig(oldConfig, newConfig.getAuth(), newBaseConfig); configValidationResult.getErrorMessages().addAll(authValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(authValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || authValidation.isRestartNeeded()); ConfigValidationResult categoriesValidation = newConfig.getCategoriesConfig().validateConfig(oldConfig, newConfig.getCategoriesConfig(), newBaseConfig); configValidationResult.getErrorMessages().addAll(categoriesValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(categoriesValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || categoriesValidation.isRestartNeeded()); ConfigValidationResult mainValidation = newConfig.getMain().validateConfig(oldConfig, newConfig.getMain(), newBaseConfig); configValidationResult.getErrorMessages().addAll(mainValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(mainValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || mainValidation.isRestartNeeded()); ConfigValidationResult searchingValidation = newConfig.getSearching().validateConfig(oldConfig, newConfig.getSearching(), newBaseConfig); configValidationResult.getErrorMessages().addAll(searchingValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(searchingValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || searchingValidation.isRestartNeeded()); ConfigValidationResult downloadingValidation = newConfig.getDownloading().validateConfig(oldConfig, newConfig.getDownloading(), newBaseConfig); configValidationResult.getErrorMessages().addAll(downloadingValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(downloadingValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || downloadingValidation.isRestartNeeded()); for (IndexerConfig indexer : newConfig.getIndexers()) { ConfigValidationResult indexerValidation = indexer.validateConfig(oldConfig, indexer, newBaseConfig); configValidationResult.getErrorMessages().addAll(indexerValidation.getErrorMessages()); configValidationResult.getWarningMessages().addAll(indexerValidation.getWarningMessages()); configValidationResult.setRestartNeeded(configValidationResult.isRestartNeeded() || indexerValidation.isRestartNeeded()); } validateIndexers(newConfig, configValidationResult); if (!configValidationResult.getErrorMessages().isEmpty()) { logger.warn("Config validation returned errors:\n" + Joiner.on("\n").join(configValidationResult.getErrorMessages())); } if (!configValidationResult.getWarningMessages().isEmpty()) { logger.warn("Config validation returned warnings:\n" + Joiner.on("\n").join(configValidationResult.getWarningMessages())); } if (configValidationResult.isRestartNeeded()) { logger.warn("Settings were changed that require a restart to become effective"); } configValidationResult.setOk(configValidationResult.getErrorMessages().isEmpty()); return configValidationResult; }  void replace(BaseConfig newConfig); void save(boolean saveInstantly); @PostConstruct void init(); void load(); @EventListener void onShutdown(ShutdownEvent event); @Override ConfigValidationResult validateConfig(BaseConfig oldConfig, BaseConfig newConfig, BaseConfig newBaseConfig); @Override BaseConfig prepareForSaving(BaseConfig oldBaseConfig); @Override BaseConfig updateAfterLoading(); @Override BaseConfig initializeNewConfig(); static boolean isProductive; }