Search in sources :

Example 11 with ConfigLocation

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

the class ConfigLoaderTest method shouldReturnFilesInConfigLocation.

@Test
public void shouldReturnFilesInConfigLocation() throws IOException {
    ConfigLocation configLocation = mock(ConfigLocation.class);
    File file = mock(File.class);
    List<File> files = Arrays.asList(file);
    when(configLocation.getExistingConfigFiles()).thenReturn(files);
    when(coreConfigurationService.getConfigLocation()).thenReturn(configLocation);
    List<File> existingConfigs = configLoader.findExistingConfigs();
    assertSame(files, existingConfigs);
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) File(java.io.File) Test(org.junit.Test)

Example 12 with ConfigLocation

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

the class ConfigLoaderTest method shouldThrowExceptionIfErrorReadingSettingsFile.

@Test(expected = MotechConfigurationException.class)
public void shouldThrowExceptionIfErrorReadingSettingsFile() throws MalformedURLException {
    ConfigLocation configLocation = mock(ConfigLocation.class);
    UrlResource resource = mock(UrlResource.class);
    when(coreConfigurationService.getConfigLocation()).thenReturn(configLocation);
    when(configLocation.toResource()).thenReturn(resource);
    when(resource.createRelative(ConfigurationConstants.SETTINGS_FILE_NAME)).thenThrow(new MalformedURLException());
    configLoader.loadMotechSettings();
}
Also used : MalformedURLException(java.net.MalformedURLException) UrlResource(org.springframework.core.io.UrlResource) ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) Test(org.junit.Test)

Example 13 with ConfigLocation

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

the class ConfigLoaderTest method shouldLoadSupportedFilesFromGivenConfigLocation.

@Test
public void shouldLoadSupportedFilesFromGivenConfigLocation() throws IOException {
    final String dirPath = FileHelper.getResourceFile("config").getAbsolutePath();
    final File file1 = new File(dirPath, "motech-settings.properties");
    final File file2 = new File(dirPath, "org.motechproject.motech-module1/somemodule.properties");
    final File file3 = new File(dirPath, "org.motechproject.motech-module2/raw/somemodule.json");
    final List<File> expectedFiles = Arrays.asList(file1, file2, file3);
    final ConfigLocation configLocation = new ConfigLocation(dirPath);
    when(coreConfigurationService.getConfigLocation()).thenReturn(configLocation);
    final List<File> actualFiles = configLoader.findExistingConfigs();
    assertEquals(expectedFiles.size(), actualFiles.size());
    assertTrue(actualFiles.containsAll(expectedFiles));
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) File(java.io.File) Test(org.junit.Test)

Example 14 with ConfigLocation

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

the class ConfigurationServiceTest method shouldIndicateThatConfigFilesAreNotRequiredWhenPlatformConfigurationFileIsPresent.

@Test
public void shouldIndicateThatConfigFilesAreNotRequiredWhenPlatformConfigurationFileIsPresent() throws IOException {
    BootstrapConfig bootstrapConfig = new BootstrapConfig(new SQLDBConfig("jdbc:mysql://localhost:3306/", "com.mysql.jdbc.Driver", null, null), ConfigSource.FILE, null, null, "tcp://localhost:61616");
    when(coreConfigurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
    ConfigLocation configLocation = mock(ConfigLocation.class);
    when(configLocation.hasPlatformConfigurationFile()).thenReturn(true);
    when(coreConfigurationService.getConfigLocation()).thenReturn(configLocation);
    assertFalse(configurationService.requiresConfigurationFiles());
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) Test(org.junit.Test)

Example 15 with ConfigLocation

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

the class ConfigurationServiceTest method shouldIndicateThatConfigFilesAreRequiredWhenPlatformConfigurationFileIsMissing.

@Test
public void shouldIndicateThatConfigFilesAreRequiredWhenPlatformConfigurationFileIsMissing() throws IOException {
    BootstrapConfig bootstrapConfig = new BootstrapConfig(new SQLDBConfig("jdbc:mysql://localhost:3306/", "com.mysql.jdbc.Driver", null, null), ConfigSource.FILE, null, null, "tcp://localhost:61616");
    when(coreConfigurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
    ConfigLocation configLocation = mock(ConfigLocation.class);
    when(configLocation.hasPlatformConfigurationFile()).thenReturn(false);
    when(coreConfigurationService.getConfigLocation()).thenReturn(configLocation);
    assertTrue(configurationService.requiresConfigurationFiles());
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) 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