Search in sources :

Example 1 with SqlDBManager

use of org.motechproject.commons.sql.service.SqlDBManager 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)

Example 2 with SqlDBManager

use of org.motechproject.commons.sql.service.SqlDBManager in project motech by motech.

the class SqlDBManagerTest method shouldProperlySetSqlProperties.

@Test
public void shouldProperlySetSqlProperties() 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}");
    propertiesToUpdate.put("some.username", "${sql.user}");
    propertiesToUpdate.put("some.password", "${sql.password}");
    propertiesToUpdate.put("quartz.delegate", "${sql.quartz.delegateClass}");
    SqlDBManager sqlDBManager = new SqlDBManagerImpl(coreConfigurationService);
    Properties propertiesAfterUpdate = sqlDBManager.getSqlProperties(propertiesToUpdate);
    assertEquals(4, propertiesAfterUpdate.size());
    assertEquals("jdbc:mysql://localhost:3306/", propertiesAfterUpdate.getProperty("javax.jdo.option.ConnectionURL"));
    assertEquals("root", propertiesAfterUpdate.getProperty("some.username"));
    assertEquals("pass", propertiesAfterUpdate.getProperty("some.password"));
    assertEquals(Drivers.QUARTZ_STD_JDBC_DELEGATE, propertiesAfterUpdate.getProperty("quartz.delegate"));
}
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

Properties (java.util.Properties)2 Test (org.junit.Test)2 SqlDBManager (org.motechproject.commons.sql.service.SqlDBManager)2 BootstrapConfig (org.motechproject.config.core.domain.BootstrapConfig)2 SQLDBConfig (org.motechproject.config.core.domain.SQLDBConfig)2