Application { private void loadRepositoryConfigurations(final File[] configDirectories, RepositoryConfigurations configurations) throws IOException { for (final File configDir : configDirectories) { InputStream is = null; try { final Properties properties = new Properties(); is = new FileInputStream(new File(configDir, getConfigurationFileName())); properties.load(is); final String repositoryName = configDir.getName(); logger.info("Loading repository config: " + repositoryName); final RepositoryConfiguration configuration = RepositoryConfiguration.create(repositoryName, properties); configuration.setPersisted(); configurations.add(configuration); } finally { IOUtils.closeQuietly(is); } } if (hasConfigurations()) { logger.info(getRepositoryConfigurationCount() + " repository configuration(s) loaded"); configured = true; } else { logger.warn("Configuration property file did exist but did not contain any configuration values"); } } Application(final ConfigDirectory configDirectory); void setScheduler(final Scheduler scheduler); @PostConstruct void init(); @ManagedOperation synchronized void reinit(); File[] getConfigDirectories(); File[] getBackupConfigDirectories(); void initCaches(); void persistRepositoryConfigurations(); void addConfiguration(final RepositoryConfiguration configuration); void deleteConfiguration(final RepositoryName name); void setConfigurationFileName(String configurationFileName); String getConfigurationFileName(); Set<RepositoryName> getRepositoryNames(); RepositoryConfiguration getConfiguration(final RepositoryName name); int getRepositoryConfigurationCount(); boolean hasConfigurations(); boolean isConfigured(); synchronized boolean isUpdating(final RepositoryName name); void setConfigPassword(final String configPassword); boolean isValidConfigPassword(final String configPassword); synchronized void setUpdatingCache(final RepositoryName name, final boolean updating); void setConfigured(final boolean configured); File getConfigurationDirectoryForRepository(final RepositoryName repositoryName); @Autowired void setCacheManagers(final List<CacheManager> cacheManagers); void setEditableConfig(final boolean editableConfig); boolean isEditableConfig(); boolean isConfigurationReloadSupported(); void setConfigurationReloadSupported(boolean configurationReloadSupported); URL getBaseURL(); static final String PROPERTY_KEY_SVENTON_BASE_URL; }
@Test public void testLoadRepositoryConfigurations() throws Exception { final MockServletContext servletContext = new MockServletContext(); servletContext.setContextPath("sventon-test"); configDirectory.setServletContext(servletContext); final String configFileName = "sventon-config-test.tmp"; final Application application = new Application(configDirectory); application.setConfigurationFileName(configFileName); final String name = "defaultsvn"; final File configDir = new File(configDirectory.getRepositoriesDirectory(), name); assertTrue(configDir.mkdirs()); final File configFile = new File(configDir, configFileName); storeProperties(configFile, createDummyConfigProperties(name)); assertFalse(application.hasConfigurations()); assertFalse(application.isConfigured()); application.loadRepositoryConfigurations(application.getConfigDirectories()); assertEquals(1, application.getRepositoryConfigurationCount()); assertTrue(application.isConfigured()); }