use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.
the class ConfigPropertiesUtilsTest method shouldThrowExceptionIfNoneOfTheFilesInTheDefaultLocationIsReadable.
@Test(expected = MotechConfigurationException.class)
public void shouldThrowExceptionIfNoneOfTheFilesInTheDefaultLocationIsReadable() {
List<ConfigLocation> configLocationList = new ArrayList<>();
ConfigLocation configLocationMock = Mockito.mock(ConfigLocation.class);
configLocationList.add(configLocationMock);
when(configLocationMock.getLocation()).thenReturn("location");
when(configLocationMock.getFile("fileName", ConfigLocation.FileAccessType.READABLE)).thenThrow(new MotechConfigurationException("File is not readable"));
when(configLocationMock.getLocation()).thenReturn("location");
ConfigPropertiesUtils.getDefaultPropertiesFile(ConfigLocation.FileAccessType.READABLE, configLocationList, "fileName");
}
use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.
the class ConfigPropertiesUtilsTest method getFile.
private File getFile() {
String tempDir = new File(System.getProperty("java.io.tmpdir"), "config").getAbsolutePath();
List<ConfigLocation> configLocationList = new ArrayList<>();
configLocationList.add(new ConfigLocation(tempDir));
File file = new File(tempDir, BootstrapManager.BOOTSTRAP_PROPERTIES);
if (file.exists()) {
file.delete();
}
return file;
}
use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.
the class CoreConfigurationServiceImpl method getConfigLocation.
@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));
}
use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.
the class BootstrapManagerTest method shouldLoadPropertiesInTheCorrectOrder.
@PrepareForTest(ConfigPropertiesUtils.class)
@Test
public void shouldLoadPropertiesInTheCorrectOrder() throws IOException {
PowerMockito.mockStatic(ConfigPropertiesUtils.class);
Iterable<ConfigLocation> configLocations = new ArrayList<ConfigLocation>();
Properties properties = createProperties();
properties.put(SQL_URL, "");
when(environment.getConfigDir()).thenReturn(null);
when(environment.getBootstrapProperties()).thenReturn(properties);
when(configLocationFileStore.getAll()).thenReturn(configLocations);
when(ConfigPropertiesUtils.getDefaultPropertiesFile(ConfigLocation.FileAccessType.READABLE, configLocations, BootstrapManager.BOOTSTRAP_PROPERTIES)).thenThrow(new MotechConfigurationException("Error loading file from config locations"));
try {
bootstrapManager.loadBootstrapConfig();
} catch (MotechConfigurationException e) {
// Ignore error because invocation order is to be verified.
}
InOrder inOrder = Mockito.inOrder(environment, configLocationFileStore);
inOrder.verify(environment).getConfigDir();
inOrder.verify(environment).getBootstrapProperties();
inOrder.verify(configLocationFileStore).getAll();
}
use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.
the class DbConfigManagerTest method shouldLoadPropertiesFromDefaultConfigLocation.
private void shouldLoadPropertiesFromDefaultConfigLocation(String filename) throws IOException {
when(environment.getDatanucleusDataProperties()).thenReturn(new Properties());
when(environment.getConfigDir()).thenReturn("");
tempDir = Files.createTempDir();
File file = new File(tempDir, filename);
List<ConfigLocation> configLocationList = new ArrayList<>();
Properties properties = getCompleteProperties(filename);
try (FileOutputStream os = new FileOutputStream(file)) {
properties.store(os, null);
}
configLocationList.add(new ConfigLocation(tempDir.getAbsolutePath()));
when(configLocationFileStore.getAll()).thenReturn(configLocationList);
properties = useDbManagerToGetCorrectFile(filename);
assertEquals(getCompleteProperties(filename), properties);
}
Aggregations