Search in sources :

Example 11 with SQLDBConfig

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

the class ConfigurationServiceTest method shouldSaveBootstrapConfig.

@Test
public void shouldSaveBootstrapConfig() throws IOException {
    BootstrapConfig bootstrapConfig = new BootstrapConfig(new SQLDBConfig("jdbc:mysql://localhost:3306/", "com.mysql.jdbc.Driver", null, null), ConfigSource.FILE, null, null, "tcp://localhost:61616");
    configurationService.save(bootstrapConfig);
    verify(coreConfigurationService).saveBootstrapConfig(bootstrapConfig);
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) Test(org.junit.Test)

Example 12 with SQLDBConfig

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

the class ConfigurationServiceTest method shouldLoadBootstrapDBConfiguration.

@Test
public void shouldLoadBootstrapDBConfiguration() {
    BootstrapConfig expectedConfig = new BootstrapConfig(new SQLDBConfig("jdbc:mysql://localhost:3306/", "com.mysql.jdbc.Driver", null, null), null, null, null, "tcp://localhost:61616");
    when(coreConfigurationService.loadBootstrapConfig()).thenReturn(expectedConfig);
    BootstrapConfig bootstrapConfig = configurationService.loadBootstrapConfig();
    assertNotNull(bootstrapConfig);
    assertThat(bootstrapConfig, IsEqual.equalTo(bootstrapConfig));
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) Test(org.junit.Test)

Example 13 with SQLDBConfig

use of org.motechproject.config.core.domain.SQLDBConfig 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 14 with SQLDBConfig

use of org.motechproject.config.core.domain.SQLDBConfig 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 15 with SQLDBConfig

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

the class SqlDBManagerImpl method loadSqlProperties.

private void loadSqlProperties() {
    sqlProperties = new Properties();
    SQLDBConfig sqlConfig = coreConfigurationService.loadBootstrapConfig().getSqlConfig();
    String sqlUrl = sqlConfig.getUrl();
    if (!sqlUrl.endsWith("/")) {
        sqlUrl.concat("/");
    }
    sqlProperties.setProperty(SQL_URL, sqlUrl);
    String sqlUser = sqlConfig.getUsername();
    if (sqlUser != null) {
        sqlProperties.setProperty(SQL_USER, sqlUser);
    }
    String sqlPassword = sqlConfig.getPassword();
    if (sqlPassword != null) {
        sqlProperties.setProperty(SQL_PASSWORD, sqlPassword);
    }
    String sqlDriver = sqlConfig.getDriver();
    if (sqlDriver != null) {
        sqlProperties.setProperty(SQL_DRIVER, sqlDriver);
    }
    String quartzDelegate = getQuartzDriverDeletegate(sqlDriver);
    sqlProperties.setProperty("sql.quartz.delegateClass", quartzDelegate);
}
Also used : Properties(java.util.Properties) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig)

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