Search in sources :

Example 6 with ConfigLocation

use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.

the class DbConfigManagerTest method shouldCopyFileWhenLoadingPropertiesFromClassPath.

private void shouldCopyFileWhenLoadingPropertiesFromClassPath(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<>();
    configLocationList.add(new ConfigLocation(tempDir.getAbsolutePath()));
    when(configLocationFileStore.getAll()).thenReturn(configLocationList);
    useDbManagerToGetCorrectFile(filename);
    Properties properties = new Properties();
    try (FileInputStream is = new FileInputStream(file)) {
        properties.load(is);
    }
    assertEquals(getCompleteProperties(filename), properties);
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) ArrayList(java.util.ArrayList) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 7 with ConfigLocation

use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.

the class ConfigLocationIT method shouldReturnConfigurationFiles.

@Test
public void shouldReturnConfigurationFiles() throws IOException {
    ConfigLocation configLocation = new ConfigLocation(getConfigDirectoryLocation("config/"));
    List<File> existingConfigFiles = configLocation.getExistingConfigFiles();
    assertThat(existingConfigFiles.isEmpty(), Is.is(false));
    assertThat(existingConfigFiles, has("motech-settings.properties"));
    assertThat(existingConfigFiles, doesNotHave("bootstrap.properties"));
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) File(java.io.File) Test(org.junit.Test)

Example 8 with ConfigLocation

use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.

the class CoreConfigurationServiceImplTest method shouldGetConfigLocation.

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

Example 9 with ConfigLocation

use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.

the class CoreConfigurationServiceImplTest method shouldThrowExceptionIfNoneOfTheConfigLocationsAreReadable.

@Test
public void shouldThrowExceptionIfNoneOfTheConfigLocationsAreReadable() {
    String inCorrectConfigPath = this.getClass().getClassLoader().getResource("some_random_dir").getPath();
    when(configLocationFileStoreMock.getAll()).thenReturn(Arrays.asList(new ConfigLocation(inCorrectConfigPath)));
    expectedException.expect(MotechConfigurationException.class);
    expectedException.expectMessage(String.format("Could not read settings from any of the config locations. Searched directories: %s .", new ConfigLocation(inCorrectConfigPath).getLocation()));
    coreConfigurationService.getConfigLocation();
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) Test(org.junit.Test)

Example 10 with ConfigLocation

use of org.motechproject.config.core.domain.ConfigLocation in project motech by motech.

the class ConfigFileMonitor method setupLocation.

private void setupLocation() throws FileSystemException {
    ConfigLocation configLocation = coreConfigurationService.getConfigLocation();
    monitoredDir = VFS.getManager().resolveFile(configLocation.getLocation());
    fileMonitor.addFile(monitoredDir);
    LOGGER.info(String.format("Setting up monitoring for location: %s", monitoredDir));
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation)

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