use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.
the class ConfigLoaderTest method testMotechSettingsLoading.
@Test
public void testMotechSettingsLoading() {
final String dirPath = FileHelper.getResourceFile("config/").getAbsolutePath();
ConfigLocation configLocation = new ConfigLocation(dirPath);
when(coreConfigurationService.getConfigLocation()).thenReturn(configLocation);
MotechSettings settings = configLoader.loadMotechSettings();
assertNotNull(settings);
assertEquals(settings.getLanguage(), "en");
}
use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.
the class ConfigFileMonitorTest method shouldUpdateFileMonitoringLocation.
@Test
public void shouldUpdateFileMonitoringLocation() throws FileSystemException {
final String fileName = "res:config/motech-settings.properties";
ConfigLocation configLocation = new ConfigLocation(fileName);
FileObject newLocation = VFS.getManager().resolveFile(fileName);
when(coreConfigurationService.getConfigLocation()).thenReturn(configLocation);
configFileMonitor.updateFileMonitor();
InOrder inOrder = inOrder(coreConfigurationService, fileMonitor);
inOrder.verify(fileMonitor).stop();
inOrder.verify(fileMonitor).removeFile(any(FileObject.class));
inOrder.verify(coreConfigurationService).getConfigLocation();
inOrder.verify(fileMonitor).addFile(newLocation);
inOrder.verify(fileMonitor).start();
}
use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.
the class ConfigFileMonitorTest method shouldProcessExistingFilesAndStartFileMonitorWhileInitializing.
@Test
public void shouldProcessExistingFilesAndStartFileMonitorWhileInitializing() throws IOException, URISyntaxException {
final Path tempDirectory = Files.createTempDirectory("motech-config-");
String configLocation = tempDirectory.toString();
when(coreConfigurationService.getConfigLocation()).thenReturn(new ConfigLocation(configLocation));
when(bootstrapConfig.getConfigSource()).thenReturn(ConfigSource.FILE);
configFileMonitor.init();
InOrder inOrder = inOrder(configLoader, configurationService, fileMonitor);
inOrder.verify(configLoader).findExistingConfigs();
inOrder.verify(configurationService).processExistingConfigs((List<File>) any());
final ArgumentCaptor<FileObject> fileObjArgCaptor = ArgumentCaptor.forClass(FileObject.class);
inOrder.verify(fileMonitor).addFile(fileObjArgCaptor.capture());
final FileObject monitoredLocation = fileObjArgCaptor.getValue();
assertEquals(configLocation, new File(monitoredLocation.getURL().toURI()).getAbsolutePath());
inOrder.verify(fileMonitor).start();
}
use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.
the class BootstrapManagerTest method mockDefaultBootstrapFile.
private File mockDefaultBootstrapFile() throws IOException {
File bootstrapConfigFile = new File(System.getProperty("user.home") + "/" + "/bootstrap.properties");
List<ConfigLocation> configLocationList = new ArrayList<>();
ConfigLocation configLocationMock = Mockito.mock(ConfigLocation.class);
configLocationList.add(configLocationMock);
when(configLocationFileStore.getAll()).thenReturn(configLocationList);
when(configLocationMock.getFile(BootstrapManager.BOOTSTRAP_PROPERTIES, READABLE)).thenReturn(bootstrapConfigFile);
when(ConfigPropertiesUtils.getDefaultPropertiesFile(ConfigLocation.FileAccessType.READABLE, configLocationList, BootstrapManager.BOOTSTRAP_PROPERTIES)).thenReturn(bootstrapConfigFile);
return bootstrapConfigFile;
}
use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.
the class BootstrapManagerTest method shouldSaveBootstrapConfigToPropertiesFileInDefaultLocation.
@Test
public void shouldSaveBootstrapConfigToPropertiesFileInDefaultLocation() throws IOException {
BootstrapConfig bootstrapConfig = new BootstrapConfig(new SQLDBConfig(sqlUrl, sqlDriver, "some_username", "some_password"), ConfigSource.FILE, felixPath, motechDir, queueUrl);
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);
when(configLocationFileStore.getAll()).thenReturn(configLocationList);
bootstrapManager.saveBootstrapConfig(bootstrapConfig);
Properties savedBootstrapProperties = new Properties();
savedBootstrapProperties.load(new FileInputStream(new File(tempDir, "bootstrap.properties")));
assertNotNull(savedBootstrapProperties);
assertThat(savedBootstrapProperties.getProperty(SQL_URL), equalTo(sqlUrl));
}
Aggregations