Search in sources :

Example 1 with BootstrapConfig

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

the class BootstrapConfigPropertyMapperTest method shouldMapToBootstrapConfigFromProperties.

@Test
public void shouldMapToBootstrapConfigFromProperties() {
    Properties bootstrapProperties = new Properties();
    bootstrapProperties.setProperty(SQL_URL, sqlUrl);
    bootstrapProperties.setProperty(SQL_DRIVER, sqlDriver);
    bootstrapProperties.setProperty(SQL_USER, sqlUsername);
    bootstrapProperties.setProperty(SQL_PASSWORD, sqlPassword);
    bootstrapProperties.setProperty(CONFIG_SOURCE, configSource.getName());
    bootstrapProperties.setProperty(QUEUE_URL, queueUrl);
    BootstrapConfig bootstrapConfig = BootstrapConfigPropertyMapper.fromProperties(bootstrapProperties);
    Assert.assertThat(bootstrapConfig.getSqlConfig().getUrl(), Matchers.is(sqlUrl));
    Assert.assertThat(bootstrapConfig.getSqlConfig().getUsername(), Matchers.is(sqlUsername));
    Assert.assertThat(bootstrapConfig.getSqlConfig().getPassword(), Matchers.is(sqlPassword));
    Assert.assertThat(bootstrapConfig.getConfigSource(), is(configSource));
    Assert.assertThat(bootstrapConfig.getQueueUrl(), is(queueUrl));
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Properties(java.util.Properties) Test(org.junit.Test)

Example 2 with BootstrapConfig

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

the class BootstrapManagerTest method shouldReturnBootstrapConfigFromFileSpecifiedInTheEnvironmentVariable.

@PrepareForTest(ConfigPropertiesUtils.class)
@Test
public void shouldReturnBootstrapConfigFromFileSpecifiedInTheEnvironmentVariable() throws IOException {
    PowerMockito.mockStatic(ConfigPropertiesUtils.class);
    when(environment.getConfigDir()).thenReturn(bootstrapFileLocation);
    Properties properties = createProperties();
    when(ConfigPropertiesUtils.getPropertiesFromFile(new File(bootstrapFile))).thenReturn(properties);
    BootstrapConfig expectedBootstrapConfig = new BootstrapConfig(new SQLDBConfig(sqlUrl, sqlDriver, sqlUsername, sqlPassword), ConfigSource.FILE, null, null, queueUrl);
    assertThat(bootstrapManager.loadBootstrapConfig(), equalTo(expectedBootstrapConfig));
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Properties(java.util.Properties) File(java.io.File) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with BootstrapConfig

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

the class BootstrapManagerTest method shouldReturnDefaultValueIfConfigSourceIsNotSpecified.

@PrepareForTest(ConfigPropertiesUtils.class)
@Test
public void shouldReturnDefaultValueIfConfigSourceIsNotSpecified() {
    PowerMockito.mockStatic(ConfigPropertiesUtils.class);
    Properties properties = createProperties();
    properties.put(BootstrapConfig.CONFIG_SOURCE, "");
    when(environment.getBootstrapProperties()).thenReturn(properties);
    BootstrapConfig expectedBootstrapConfig = new BootstrapConfig(new SQLDBConfig(sqlUrl, sqlDriver, sqlUsername, sqlPassword), ConfigSource.UI, null, null, queueUrl);
    BootstrapConfig actualBootStrapConfig = bootstrapManager.loadBootstrapConfig();
    assertThat(actualBootStrapConfig, equalTo(expectedBootstrapConfig));
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Properties(java.util.Properties) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with BootstrapConfig

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

the class BootstrapManagerTest method shouldReturnBootStrapConfigFromFileAtDefaultLocation_If_NoEnvironmentVariablesAreSpecified.

@PrepareForTest(ConfigPropertiesUtils.class)
@Test
public void shouldReturnBootStrapConfigFromFileAtDefaultLocation_If_NoEnvironmentVariablesAreSpecified() throws IOException {
    PowerMockito.mockStatic(ConfigPropertiesUtils.class);
    Properties environmentProperties = createProperties();
    environmentProperties.put(BootstrapConfig.SQL_URL, "");
    environmentProperties.put(BootstrapConfig.SQL_DRIVER, "");
    environmentProperties.put(BootstrapConfig.QUEUE_URL, "");
    when(environment.getBootstrapProperties()).thenReturn(new Properties());
    File bootstrapConfigFile = mockDefaultBootstrapFile();
    Properties properties = new Properties();
    properties.setProperty(BootstrapConfig.SQL_URL, sqlUrl);
    properties.setProperty(BootstrapConfig.SQL_DRIVER, sqlDriver);
    properties.setProperty(BootstrapConfig.QUEUE_URL, queueUrl);
    when(ConfigPropertiesUtils.getPropertiesFromFile(bootstrapConfigFile)).thenReturn(properties);
    assertThat(bootstrapManager.loadBootstrapConfig(), equalTo(new BootstrapConfig(new SQLDBConfig(sqlUrl, sqlDriver, null, null), ConfigSource.UI, null, null, queueUrl)));
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Properties(java.util.Properties) File(java.io.File) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with BootstrapConfig

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

the class BootstrapManagerImpl method readBootstrapConfigFromEnvironment.

private BootstrapConfig readBootstrapConfigFromEnvironment() {
    Properties bootstrapProperties = environment.getBootstrapProperties();
    String sqlUrl = bootstrapProperties.getProperty(BootstrapConfig.SQL_URL);
    String sqlUsername = bootstrapProperties.getProperty(BootstrapConfig.SQL_USER);
    String sqlPassword = bootstrapProperties.getProperty(BootstrapConfig.SQL_PASSWORD);
    String configSource = bootstrapProperties.getProperty(BootstrapConfig.CONFIG_SOURCE);
    String sqlDriver = bootstrapProperties.getProperty(BootstrapConfig.SQL_DRIVER);
    String osgiStorage = bootstrapProperties.getProperty(BootstrapConfig.OSGI_FRAMEWORK_STORAGE);
    String motechDir = bootstrapProperties.getProperty(BootstrapConfig.MOTECH_DIR);
    String queueURL = bootstrapProperties.getProperty(BootstrapConfig.QUEUE_URL);
    Properties activeMqProperties = environment.getActiveMqProperties();
    return new BootstrapConfig(new SQLDBConfig(sqlUrl, sqlDriver, sqlUsername, sqlPassword), ConfigSource.valueOf(configSource), osgiStorage, motechDir, queueURL, activeMqProperties);
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Properties(java.util.Properties) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig)

Aggregations

BootstrapConfig (org.motechproject.config.core.domain.BootstrapConfig)30 Test (org.junit.Test)23 SQLDBConfig (org.motechproject.config.core.domain.SQLDBConfig)17 Properties (java.util.Properties)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 File (java.io.File)4 Locale (java.util.Locale)3 PostConstruct (javax.annotation.PostConstruct)3 ConfigLocation (org.motechproject.config.core.domain.ConfigLocation)3 StartupViewData (org.motechproject.server.web.dto.StartupViewData)3 ArrayList (java.util.ArrayList)2 SqlDBManager (org.motechproject.commons.sql.service.SqlDBManager)2 MotechConfigurationException (org.motechproject.config.core.exception.MotechConfigurationException)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 FileInputStream (java.io.FileInputStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 DefaultFileMonitor (org.apache.commons.vfs2.impl.DefaultFileMonitor)1