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());
}
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());
}
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;
}
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);
}
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());
}
Aggregations