Search in sources :

Example 16 with ConfigLocation

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");
}
Also used : MotechSettings(org.motechproject.config.domain.MotechSettings) ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) Test(org.junit.Test)

Example 17 with ConfigLocation

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();
}
Also used : InOrder(org.mockito.InOrder) ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) FileObject(org.apache.commons.vfs2.FileObject) Test(org.junit.Test)

Example 18 with ConfigLocation

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();
}
Also used : Path(java.nio.file.Path) InOrder(org.mockito.InOrder) ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File) Test(org.junit.Test)

Example 19 with ConfigLocation

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;
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) ArrayList(java.util.ArrayList) File(java.io.File)

Example 20 with ConfigLocation

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));
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) ArrayList(java.util.ArrayList) Properties(java.util.Properties) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) File(java.io.File) FileInputStream(java.io.FileInputStream) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ConfigLocation (org.motechproject.config.core.domain.ConfigLocation)24 Test (org.junit.Test)17 File (java.io.File)9 ArrayList (java.util.ArrayList)7 Properties (java.util.Properties)4 MotechConfigurationException (org.motechproject.config.core.exception.MotechConfigurationException)4 InOrder (org.mockito.InOrder)3 BootstrapConfig (org.motechproject.config.core.domain.BootstrapConfig)3 SQLDBConfig (org.motechproject.config.core.domain.SQLDBConfig)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 FileObject (org.apache.commons.vfs2.FileObject)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Resource (org.springframework.core.io.Resource)2 FileOutputStream (java.io.FileOutputStream)1 MalformedURLException (java.net.MalformedURLException)1 Path (java.nio.file.Path)1 PropertiesConfiguration (org.apache.commons.configuration.PropertiesConfiguration)1 MotechSettings (org.motechproject.config.domain.MotechSettings)1 SettingsRecord (org.motechproject.config.domain.SettingsRecord)1