Search in sources :

Example 21 with ConfigLocation

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

the class ConfigLocationFileStoreIT method shouldSubstituteHomeDirectoryInThePath.

@Test
public void shouldSubstituteHomeDirectoryInThePath() throws ConfigurationException, IOException {
    PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(getClass().getClassLoader().getResource("config-locations.properties"));
    ConfigLocationFileStore configLocationFileStore = new ConfigLocationFileStore(propertiesConfiguration);
    Iterable<ConfigLocation> configLocationsIterable = configLocationFileStore.getAll();
    assertNotNull(configLocationsIterable);
    Iterator<ConfigLocation> configLocationIterator = configLocationsIterable.iterator();
    assertTrue(configLocationIterator.hasNext());
    ConfigLocation expected = new ConfigLocation(String.format("%s/.motech/configtest/", System.getProperty("user.home")));
    assertThat(configLocationIterator.next(), IsEqual.equalTo(expected));
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) PropertiesConfiguration(org.apache.commons.configuration.PropertiesConfiguration) Test(org.junit.Test)

Example 22 with ConfigLocation

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

the class ConfigLocationIT method shouldReturnFalseWhenConfigLocationHasPlatformConfigurationFile.

@Test
public void shouldReturnFalseWhenConfigLocationHasPlatformConfigurationFile() throws IOException {
    ConfigLocation configLocation = new ConfigLocation(getConfigDirectoryLocation("some_random_dir/"));
    assertFalse(configLocation.hasPlatformConfigurationFile());
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) Test(org.junit.Test)

Example 23 with ConfigLocation

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

the class ConfigLocationIT method shouldReturnTrueWhenConfigLocationHasPlatformConfigurationFile.

@Test
public void shouldReturnTrueWhenConfigLocationHasPlatformConfigurationFile() throws IOException {
    ConfigLocation configLocation = new ConfigLocation(getConfigDirectoryLocation("config/"));
    assertTrue(configLocation.hasPlatformConfigurationFile());
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) Test(org.junit.Test)

Example 24 with ConfigLocation

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

the class ConfigLoader method loadMotechSettings.

/**
 * Loads MOTECH settings containing core platform settings.
 *
 * @return the {SettingsRecord} object
 */
public SettingsRecord loadMotechSettings() {
    SettingsRecord settingsRecord;
    ConfigLocation configLocation = coreConfigurationService.getConfigLocation();
    Resource configLocationResource = configLocation.toResource();
    try {
        Resource motechSettings = configLocationResource.createRelative(ConfigurationConstants.SETTINGS_FILE_NAME);
        settingsRecord = loadSettingsFromStream(motechSettings);
        settingsRecord.setFilePath(configLocationResource.getURL().getPath());
        checkSettingsRecord(settingsRecord);
    } catch (IOException e) {
        throw new MotechConfigurationException(String.format("Could not read settings from file at location %s", configLocation), e);
    }
    return settingsRecord;
}
Also used : SettingsRecord(org.motechproject.config.domain.SettingsRecord) ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) Resource(org.springframework.core.io.Resource) IOException(java.io.IOException) MotechConfigurationException(org.motechproject.config.core.exception.MotechConfigurationException)

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