Search in sources :

Example 16 with BootstrapConfig

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

the class ConfigurationServiceTest method shouldIndicateThatConfigFilesAreNotRequiredWhenConfigSourceIsUI.

@Test
public void shouldIndicateThatConfigFilesAreNotRequiredWhenConfigSourceIsUI() throws IOException {
    BootstrapConfig bootstrapConfig = new BootstrapConfig(new SQLDBConfig("jdbc:mysql://localhost:3306/", "com.mysql.jdbc.Driver", null, null), ConfigSource.UI, null, null, "tcp://localhost:61616");
    when(coreConfigurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
    assertFalse(configurationService.requiresConfigurationFiles());
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) Test(org.junit.Test)

Example 17 with BootstrapConfig

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

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

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

the class ConfigurationServiceBundleIT method shouldSaveBootstrapConfigToDefaultLocationAndLoadFromTheSameLocation.

@Test
public void shouldSaveBootstrapConfigToDefaultLocationAndLoadFromTheSameLocation() {
    BootstrapConfig existingBootstrapConfig = configurationService.loadBootstrapConfig();
    BootstrapConfig bootstrapConfig = new BootstrapConfig(existingBootstrapConfig.getSqlConfig(), existingBootstrapConfig.getConfigSource(), "./felix", motechDir, existingBootstrapConfig.getQueueUrl(), existingBootstrapConfig.getActiveMqProperties());
    configurationService.save(bootstrapConfig);
    assertThat(configurationService.loadBootstrapConfig(), IsEqual.equalTo(bootstrapConfig));
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) Test(org.junit.Test)

Example 20 with BootstrapConfig

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

the class BootstrapControllerTest method shouldAddErrorOnSaveAndReturnTheSameBootstrapStartupView.

@Test
public void shouldAddErrorOnSaveAndReturnTheSameBootstrapStartupView() throws Exception {
    when(messageBrokerTestService.pingBroker("tcp://localhost:61616")).thenReturn(true);
    when(localeResolver.resolveLocale(any(HttpServletRequest.class))).thenReturn(Locale.ENGLISH);
    when(messageSource.getMessage("server.error.bootstrap.save", null, Locale.ENGLISH)).thenReturn("errMsg");
    doThrow(new MotechConfigurationException("Test Exception")).when(OsgiListener.class);
    OsgiListener.saveBootstrapConfig(any(BootstrapConfig.class));
    MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/bootstrap/").param("sqlUrl", "jdbc:mysql://www.someurl.com:3306/").param("sqlDriver", "com.mysql.jdbc.Driver").param("sqlUsername", "some_username").param("sqlPassword", "some_password").param("configSource", "UI").param("queueUrl", "tcp://localhost:61616")).andExpect(MockMvcResultMatchers.status().isOk()).andReturn();
    ModelAndView actualView = mvcResult.getModelAndView();
    assertThat(actualView.getViewName(), is("bootstrapconfig"));
    assertThat((String) ((List) actualView.getModel().get("errors")).get(0), is("errMsg"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) ModelAndView(org.springframework.web.servlet.ModelAndView) List(java.util.List) MotechConfigurationException(org.motechproject.config.core.exception.MotechConfigurationException) MvcResult(org.springframework.test.web.server.MvcResult) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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