Search in sources :

Example 1 with SQLDBConfig

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));
}
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 2 with SQLDBConfig

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));
}
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 3 with SQLDBConfig

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)));
}
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 4 with SQLDBConfig

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);
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Properties(java.util.Properties) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig)

Example 5 with SQLDBConfig

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"));
}
Also used : SqlDBManager(org.motechproject.commons.sql.service.SqlDBManager) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Properties(java.util.Properties) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) Test(org.junit.Test)

Aggregations

SQLDBConfig (org.motechproject.config.core.domain.SQLDBConfig)18 BootstrapConfig (org.motechproject.config.core.domain.BootstrapConfig)17 Test (org.junit.Test)15 Properties (java.util.Properties)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 File (java.io.File)3 ConfigLocation (org.motechproject.config.core.domain.ConfigLocation)3 SqlDBManager (org.motechproject.commons.sql.service.SqlDBManager)2 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1