Search in sources :

Example 21 with BootstrapConfig

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

the class BootstrapManagerTest method shouldReturnBootStrapConfigValuesFromEnvironmentVariableWhenMotechConfigDirIsNotSpecified.

@PrepareForTest(ConfigPropertiesUtils.class)
@Test
public void shouldReturnBootStrapConfigValuesFromEnvironmentVariableWhenMotechConfigDirIsNotSpecified() throws IOException {
    PowerMockito.mockStatic(ConfigPropertiesUtils.class);
    when(environment.getConfigDir()).thenReturn(null);
    when(environment.getBootstrapProperties()).thenReturn(createProperties());
    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) 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 22 with BootstrapConfig

use of org.motechproject.config.core.domain.BootstrapConfig 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)

Example 23 with BootstrapConfig

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

the class BootstrapManagerImpl method getActiveMqConfig.

@Override
public Properties getActiveMqConfig() {
    BootstrapConfig bootstrapConfig = loadBootstrapConfig();
    Properties activeMqProperties = bootstrapConfig.getActiveMqProperties();
    if (activeMqProperties == null) {
        return new Properties();
    }
    replaceQueueNames(activeMqProperties);
    return activeMqProperties;
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Properties(java.util.Properties)

Example 24 with BootstrapConfig

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

the class BootstrapConfigPropertyMapperTest method shouldMapToPropertiesFromBootstrapConfig_WhenUsernameAndPasswordAreBlank.

@Test
public void shouldMapToPropertiesFromBootstrapConfig_WhenUsernameAndPasswordAreBlank() {
    Properties bootstrapProperties = BootstrapConfigPropertyMapper.toProperties(new BootstrapConfig(new SQLDBConfig(sqlUrl, sqlDriver, sqlUsername, sqlPassword), configSource, felixPath, motechDir, queueUrl));
    Assert.assertThat(bootstrapProperties.getProperty(sqlUsername), nullValue());
    Assert.assertThat(bootstrapProperties.getProperty(sqlPassword), nullValue());
    Assert.assertThat(bootstrapProperties.getProperty(CONFIG_SOURCE), is(configSource.getName()));
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Properties(java.util.Properties) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) Test(org.junit.Test)

Example 25 with BootstrapConfig

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

the class BootstrapConfigPropertyMapperTest method shouldMapToPropertiesFromBootstrapConfig.

@Test
public void shouldMapToPropertiesFromBootstrapConfig() {
    Properties bootstrapProperties = BootstrapConfigPropertyMapper.toProperties(new BootstrapConfig(new SQLDBConfig(sqlUrl, sqlDriver, sqlUsername, sqlPassword), configSource, felixPath, motechDir, queueUrl));
    Assert.assertThat(bootstrapProperties.getProperty(CONFIG_SOURCE), is(configSource.getName()));
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Properties(java.util.Properties) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) Test(org.junit.Test)

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