Search in sources :

Example 26 with BootstrapConfig

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

the class CoreConfigurationBundleIT method testBootstrapConfigBundleIT.

@Test
public void testBootstrapConfigBundleIT() {
    BootstrapConfig bootstrapConfig = coreConfigurationService.loadBootstrapConfig();
    assertNotNull(bootstrapConfig);
    assertNotNull(bootstrapConfig.getSqlConfig());
    assertNotNull(bootstrapConfig.getConfigSource());
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Test(org.junit.Test)

Example 27 with BootstrapConfig

use of org.motechproject.config.core.domain.BootstrapConfig 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)

Example 28 with BootstrapConfig

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

the class StartupControllerTest method shouldInformViewThatConfigFilesNotRequiredWhenConfigSourceIsFileAndConfigFilesExist.

@Test
public void shouldInformViewThatConfigFilesNotRequiredWhenConfigSourceIsFileAndConfigFilesExist() throws IOException {
    when(configurationService.requiresConfigurationFiles()).thenReturn(true);
    when(localeService.getUserLocale(httpServletRequest)).thenReturn(new Locale("en"));
    BootstrapConfig bootstrapConfig = mock(BootstrapConfig.class);
    when(bootstrapConfig.getConfigSource()).thenReturn(ConfigSource.FILE);
    when(configurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
    when(configurationService.requiresConfigurationFiles()).thenReturn(false);
    StartupViewData startupViewData = startupController.getStartupViewData(httpServletRequest);
    assertThat((startupViewData.getRequireConfigFiles()), Is.is(false));
    verify(configurationService).requiresConfigurationFiles();
}
Also used : Locale(java.util.Locale) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) StartupViewData(org.motechproject.server.web.dto.StartupViewData) Test(org.junit.Test)

Example 29 with BootstrapConfig

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

the class StartupControllerTest method shouldInformViewThatConfigFilesRequiredWhenConfigSourceIsFileAndConfigFilesDoNotExist.

@Test
public void shouldInformViewThatConfigFilesRequiredWhenConfigSourceIsFileAndConfigFilesDoNotExist() throws IOException {
    when(configurationService.requiresConfigurationFiles()).thenReturn(true);
    when(localeService.getUserLocale(httpServletRequest)).thenReturn(new Locale("en"));
    BootstrapConfig bootstrapConfig = mock(BootstrapConfig.class);
    when(bootstrapConfig.getConfigSource()).thenReturn(ConfigSource.FILE);
    when(configurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
    when(configurationService.requiresConfigurationFiles()).thenReturn(true);
    StartupViewData startupViewData = startupController.getStartupViewData(httpServletRequest);
    assertThat((startupViewData.getRequireConfigFiles()), Is.is(true));
    verify(configurationService).requiresConfigurationFiles();
}
Also used : Locale(java.util.Locale) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) StartupViewData(org.motechproject.server.web.dto.StartupViewData) Test(org.junit.Test)

Example 30 with BootstrapConfig

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

the class StartupManagerTest method shouldNotTryToLoadDbSettingsIfConfigurationFilesAreStillRequired.

@Test
public void shouldNotTryToLoadDbSettingsIfConfigurationFilesAreStillRequired() {
    BootstrapConfig bootstrap = mock(BootstrapConfig.class);
    when(configurationService.loadBootstrapConfig()).thenReturn(bootstrap);
    when(configurationService.requiresConfigurationFiles()).thenReturn(true);
    startupManager.startup();
    assertFalse(startupManager.isBootstrapConfigRequired());
    assertTrue(startupManager.isConfigRequired());
    verify(configurationService, never()).getPlatformSettings();
    verify(configurationService).requiresConfigurationFiles();
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Test(org.junit.Test)

Aggregations

BootstrapConfig (org.motechproject.config.core.domain.BootstrapConfig)30 Test (org.junit.Test)23 SQLDBConfig (org.motechproject.config.core.domain.SQLDBConfig)17 Properties (java.util.Properties)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 File (java.io.File)4 Locale (java.util.Locale)3 PostConstruct (javax.annotation.PostConstruct)3 ConfigLocation (org.motechproject.config.core.domain.ConfigLocation)3 StartupViewData (org.motechproject.server.web.dto.StartupViewData)3 ArrayList (java.util.ArrayList)2 SqlDBManager (org.motechproject.commons.sql.service.SqlDBManager)2 MotechConfigurationException (org.motechproject.config.core.exception.MotechConfigurationException)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 FileInputStream (java.io.FileInputStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 DefaultFileMonitor (org.apache.commons.vfs2.impl.DefaultFileMonitor)1