use of org.motechproject.config.core.domain.SQLDBConfig 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.SQLDBConfig 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.SQLDBConfig 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.SQLDBConfig 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);
}
use of org.motechproject.config.core.domain.SQLDBConfig in project motech by motech.
the class SqlDBManagerTest method shouldARemoveSlash.
@Test
public void shouldARemoveSlash() throws IOException {
BootstrapConfig bootstrapConfig = new BootstrapConfig(new SQLDBConfig("jdbc:mysql://localhost:3306/", "com.mysql.jdbc.Driver", "root", "pass"), ConfigSource.FILE, "./felix", motechDir, "tcp://localhost:61616");
when(coreConfigurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
Properties propertiesToUpdate = new Properties();
propertiesToUpdate.put("javax.jdo.option.ConnectionURL", "${sql.url}dbname?useSSL=true");
SqlDBManager sqlDBManager = new SqlDBManagerImpl(coreConfigurationService);
Properties propertiesAfterUpdate = sqlDBManager.getSqlProperties(propertiesToUpdate);
assertEquals("jdbc:mysql://localhost:3306/dbname?useSSL=true", propertiesAfterUpdate.getProperty("javax.jdo.option.ConnectionURL"));
propertiesToUpdate = new Properties();
propertiesToUpdate.put("javax.jdo.option.ConnectionURL", "${sql.url}/dbname?useSSL=true");
propertiesAfterUpdate = sqlDBManager.getSqlProperties(propertiesToUpdate);
assertEquals("jdbc:mysql://localhost:3306/dbname?useSSL=true", propertiesAfterUpdate.getProperty("javax.jdo.option.ConnectionURL"));
}
Aggregations