Search in sources :

Example 6 with SQLDBConfig

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

the class ConfigurationServiceTest method shouldIndicateThatConfigFilesAreNotRequiredWhenPlatformConfigurationFileIsPresent.

@Test
public void shouldIndicateThatConfigFilesAreNotRequiredWhenPlatformConfigurationFileIsPresent() 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");
    when(coreConfigurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
    ConfigLocation configLocation = mock(ConfigLocation.class);
    when(configLocation.hasPlatformConfigurationFile()).thenReturn(true);
    when(coreConfigurationService.getConfigLocation()).thenReturn(configLocation);
    assertFalse(configurationService.requiresConfigurationFiles());
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) Test(org.junit.Test)

Example 7 with SQLDBConfig

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

the class ConfigurationServiceTest method shouldIndicateThatConfigFilesAreRequiredWhenPlatformConfigurationFileIsMissing.

@Test
public void shouldIndicateThatConfigFilesAreRequiredWhenPlatformConfigurationFileIsMissing() 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");
    when(coreConfigurationService.loadBootstrapConfig()).thenReturn(bootstrapConfig);
    ConfigLocation configLocation = mock(ConfigLocation.class);
    when(configLocation.hasPlatformConfigurationFile()).thenReturn(false);
    when(coreConfigurationService.getConfigLocation()).thenReturn(configLocation);
    assertTrue(configurationService.requiresConfigurationFiles());
}
Also used : ConfigLocation(org.motechproject.config.core.domain.ConfigLocation) BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) Test(org.junit.Test)

Example 8 with SQLDBConfig

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

the class BootstrapController method submitForm.

@RequestMapping(value = "/", method = RequestMethod.POST)
public ModelAndView submitForm(@ModelAttribute(BOOTSTRAP_CONFIG) @Valid BootstrapConfigForm form, BindingResult result, HttpServletRequest request) {
    if (OsgiListener.isBootstrapPresent()) {
        return new ModelAndView(REDIRECT_HOME);
    }
    if (result.hasErrors()) {
        ModelAndView bootstrapView = new ModelAndView(BOOTSTRAP_CONFIG_VIEW);
        bootstrapView.addObject("errors", getErrors(result));
        addCommonBootstrapViewObjects(bootstrapView);
        return bootstrapView;
    }
    String queueUrl = form.getQueueUrl();
    boolean reachable = messageBrokerPingService.pingBroker(queueUrl);
    if (!reachable) {
        ModelAndView bootstrapView = new ModelAndView(BOOTSTRAP_CONFIG_VIEW);
        bootstrapView.addObject(ERRORS, singletonList(getMessage("server.bootstrap.verify.amq.warning", new Object[] { queueUrl }, request)));
        addCommonBootstrapViewObjects(bootstrapView);
        return bootstrapView;
    }
    BootstrapConfig bootstrapConfig;
    if (form.getOsgiFrameworkStorage() != null) {
        bootstrapConfig = new BootstrapConfig(new SQLDBConfig(form.getSqlUrl(), form.getSqlDriver(), form.getSqlUsername(), form.getSqlPassword()), ConfigSource.valueOf(form.getConfigSource()), form.getOsgiFrameworkStorage(), form.getMotechDir(), form.getQueueUrl());
    } else {
        bootstrapConfig = new BootstrapConfig(new SQLDBConfig(form.getSqlUrl(), form.getSqlDriver(), form.getSqlUsername(), form.getSqlPassword()), ConfigSource.valueOf(form.getConfigSource()), null, form.getMotechDir(), form.getQueueUrl());
    }
    try {
        OsgiListener.saveBootstrapConfig(bootstrapConfig);
    } catch (RuntimeException e) {
        LOGGER.error("Error while saving bootstrap configuration", e);
        ModelAndView bootstrapView = new ModelAndView(BOOTSTRAP_CONFIG_VIEW);
        bootstrapView.addObject("errors", singletonList(getMessage("server.error.bootstrap.save", request)));
        addCommonBootstrapViewObjects(bootstrapView);
        return bootstrapView;
    }
    ModelAndView bootstrapView = new ModelAndView(BOOTSTRAP_CONFIG_VIEW);
    bootstrapView.getModelMap().put("redirect", true);
    return bootstrapView;
}
Also used : BootstrapConfig(org.motechproject.config.core.domain.BootstrapConfig) ModelAndView(org.springframework.web.servlet.ModelAndView) SQLDBConfig(org.motechproject.config.core.domain.SQLDBConfig) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with SQLDBConfig

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

the class BootstrapControllerTest method shouldSaveBootstrapConfig.

@Test
public void shouldSaveBootstrapConfig() throws Exception {
    when(messageBrokerTestService.pingBroker("tcp://localhost:61616")).thenReturn(true);
    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()).andExpect(MockMvcResultMatchers.view().name("bootstrapconfig")).andExpect(MockMvcResultMatchers.model().attribute("redirect", true));
    BootstrapConfig expectedConfigToSave = new BootstrapConfig(new SQLDBConfig("jdbc:mysql://www.someurl.com:3306/", "com.mysql.jdbc.Driver", "some_username", "some_password"), ConfigSource.valueOf("UI"), "./felix", motechDir, "tcp://localhost:61616");
    PowerMockito.verifyStatic(times(1));
    OsgiListener.saveBootstrapConfig(expectedConfigToSave);
}
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)

Example 10 with SQLDBConfig

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

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