@Test public void shouldGetConfigLocation() { String correctConfigPath = this.getClass().getClassLoader().getResource("config").getPath(); String inCorrectConfigPath = this.getClass().getClassLoader().getResource("some_random_dir").getPath(); ConfigLocation incorrectLocation = new ConfigLocation(inCorrectConfigPath); ConfigLocation correctLocation = new ConfigLocation(correctConfigPath); when(configLocationFileStoreMock.getAll()).thenReturn(Arrays.asList(incorrectLocation, correctLocation)); ConfigLocation configLocation = coreConfigurationService.getConfigLocation(); assertEquals(correctLocation, configLocation); }
@Override public ConfigLocation getConfigLocation() { Iterable<ConfigLocation> locations = configLocationFileStore.getAll(); StringBuilder sb = new StringBuilder(""); for (ConfigLocation configLocation : locations) { sb.append(configLocation.getLocation()).append(' '); Resource configLocationResource = configLocation.toResource(); try { Resource motechSettings = configLocationResource.createRelative(ConfigurationConstants.SETTINGS_FILE_NAME); if (motechSettings.isReadable() && locations != null) { return configLocation; } LOGGER.warn("Could not read motech-settings.properties from: " + configLocationResource.toString()); } catch (IOException e) { LOGGER.warn("Problem reading motech-settings.properties from location: " + configLocationResource.toString(), e); } } throw new MotechConfigurationException(String.format("Could not read settings from any of the config locations. Searched directories: %s.", sb)); }
CoreConfigurationServiceImpl implements CoreConfigurationService { @Override public ConfigLocation getConfigLocation() { Iterable<ConfigLocation> locations = configLocationFileStore.getAll(); StringBuilder sb = new StringBuilder(""); for (ConfigLocation configLocation : locations) { sb.append(configLocation.getLocation()).append(' '); Resource configLocationResource = configLocation.toResource(); try { Resource motechSettings = configLocationResource.createRelative(ConfigurationConstants.SETTINGS_FILE_NAME); if (motechSettings.isReadable() && locations != null) { return configLocation; } LOGGER.warn("Could not read motech-settings.properties from: " + configLocationResource.toString()); } catch (IOException e) { LOGGER.warn("Problem reading motech-settings.properties from location: " + configLocationResource.toString(), e); } } throw new MotechConfigurationException(String.format("Could not read settings from any of the config locations. Searched directories: %s.", sb)); } }
CoreConfigurationServiceImpl implements CoreConfigurationService { @Override public ConfigLocation getConfigLocation() { Iterable<ConfigLocation> locations = configLocationFileStore.getAll(); StringBuilder sb = new StringBuilder(""); for (ConfigLocation configLocation : locations) { sb.append(configLocation.getLocation()).append(' '); Resource configLocationResource = configLocation.toResource(); try { Resource motechSettings = configLocationResource.createRelative(ConfigurationConstants.SETTINGS_FILE_NAME); if (motechSettings.isReadable() && locations != null) { return configLocation; } LOGGER.warn("Could not read motech-settings.properties from: " + configLocationResource.toString()); } catch (IOException e) { LOGGER.warn("Problem reading motech-settings.properties from location: " + configLocationResource.toString(), e); } } throw new MotechConfigurationException(String.format("Could not read settings from any of the config locations. Searched directories: %s.", sb)); } @Autowired  CoreConfigurationServiceImpl(BootstrapManager bootstrapManager, DbConfigManager dbConfigManager, ConfigLocationFileStore configLocationFileStore); }
CoreConfigurationServiceImpl implements CoreConfigurationService { @Override public ConfigLocation getConfigLocation() { Iterable<ConfigLocation> locations = configLocationFileStore.getAll(); StringBuilder sb = new StringBuilder(""); for (ConfigLocation configLocation : locations) { sb.append(configLocation.getLocation()).append(' '); Resource configLocationResource = configLocation.toResource(); try { Resource motechSettings = configLocationResource.createRelative(ConfigurationConstants.SETTINGS_FILE_NAME); if (motechSettings.isReadable() && locations != null) { return configLocation; } LOGGER.warn("Could not read motech-settings.properties from: " + configLocationResource.toString()); } catch (IOException e) { LOGGER.warn("Problem reading motech-settings.properties from location: " + configLocationResource.toString(), e); } } throw new MotechConfigurationException(String.format("Could not read settings from any of the config locations. Searched directories: %s.", sb)); } @Autowired  CoreConfigurationServiceImpl(BootstrapManager bootstrapManager, DbConfigManager dbConfigManager, ConfigLocationFileStore configLocationFileStore); @Override @Caching(cacheable = {@Cacheable(value = CORE_SETTINGS_CACHE_NAME, key = ROOT_METHOD_NAME) }) BootstrapConfig loadBootstrapConfig(); @Override @Caching(cacheable = {@Cacheable(value = CORE_SETTINGS_CACHE_NAME, key = ROOT_METHOD_NAME) }) Properties loadDatanucleusDataConfig(); @Override @Caching(cacheable = {@Cacheable(value = CORE_SETTINGS_CACHE_NAME, key = ROOT_METHOD_NAME) }) Properties loadDatanucleusSchemaConfig(); @Override @Caching(cacheable = {@Cacheable(value = CORE_SETTINGS_CACHE_NAME, key = ROOT_METHOD_NAME) }) Properties loadFlywayDataConfig(); @Override @Caching(cacheable = {@Cacheable(value = CORE_SETTINGS_CACHE_NAME, key = ROOT_METHOD_NAME) }) Properties loadFlywaySchemaConfig(); @Override void saveBootstrapConfig(BootstrapConfig bootstrapConfig); @Override ConfigLocation getConfigLocation(); @Override void addConfigLocation(String location); @Override Properties getActiveMqConfig(); @Override void evictMotechCoreSettingsCache(); }
CoreConfigurationServiceImpl implements CoreConfigurationService { @Override public ConfigLocation getConfigLocation() { Iterable<ConfigLocation> locations = configLocationFileStore.getAll(); StringBuilder sb = new StringBuilder(""); for (ConfigLocation configLocation : locations) { sb.append(configLocation.getLocation()).append(' '); Resource configLocationResource = configLocation.toResource(); try { Resource motechSettings = configLocationResource.createRelative(ConfigurationConstants.SETTINGS_FILE_NAME); if (motechSettings.isReadable() && locations != null) { return configLocation; } LOGGER.warn("Could not read motech-settings.properties from: " + configLocationResource.toString()); } catch (IOException e) { LOGGER.warn("Problem reading motech-settings.properties from location: " + configLocationResource.toString(), e); } } throw new MotechConfigurationException(String.format("Could not read settings from any of the config locations. Searched directories: %s.", sb)); } @Autowired  CoreConfigurationServiceImpl(BootstrapManager bootstrapManager, DbConfigManager dbConfigManager, ConfigLocationFileStore configLocationFileStore); @Override @Caching(cacheable = {@Cacheable(value = CORE_SETTINGS_CACHE_NAME, key = ROOT_METHOD_NAME) }) BootstrapConfig loadBootstrapConfig(); @Override @Caching(cacheable = {@Cacheable(value = CORE_SETTINGS_CACHE_NAME, key = ROOT_METHOD_NAME) }) Properties loadDatanucleusDataConfig(); @Override @Caching(cacheable = {@Cacheable(value = CORE_SETTINGS_CACHE_NAME, key = ROOT_METHOD_NAME) }) Properties loadDatanucleusSchemaConfig(); @Override @Caching(cacheable = {@Cacheable(value = CORE_SETTINGS_CACHE_NAME, key = ROOT_METHOD_NAME) }) Properties loadFlywayDataConfig(); @Override @Caching(cacheable = {@Cacheable(value = CORE_SETTINGS_CACHE_NAME, key = ROOT_METHOD_NAME) }) Properties loadFlywaySchemaConfig(); @Override void saveBootstrapConfig(BootstrapConfig bootstrapConfig); @Override ConfigLocation getConfigLocation(); @Override void addConfigLocation(String location); @Override Properties getActiveMqConfig(); @Override void evictMotechCoreSettingsCache();  }