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));
}
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));
}
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));
}
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)));
}
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);
}
Aggregations