use of org.motechproject.config.core.exception.MotechConfigurationException in project motech by motech.
the class ConfigFileMonitorTest method shouldNotStartFileMonitorIfConfigLoaderThrowsException.
@Test
public void shouldNotStartFileMonitorIfConfigLoaderThrowsException() throws IOException {
doThrow(new MotechConfigurationException("file could not be read")).when(configLoader).findExistingConfigs();
configFileMonitor.init();
verify(configurationService, never()).processExistingConfigs(anyList());
verify(fileMonitor, never()).run();
}
use of org.motechproject.config.core.exception.MotechConfigurationException in project motech by motech.
the class SettingsFacadeTest method shouldThrowExceptionsComingFromService.
@Test(expected = MotechConfigurationException.class)
public void shouldThrowExceptionsComingFromService() throws IOException {
when(configurationService.registersProperties(anyString(), anyString())).thenThrow(new MotechConfigurationException("file could not be read"));
setUpConfig();
}
use of org.motechproject.config.core.exception.MotechConfigurationException 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"));
}
use of org.motechproject.config.core.exception.MotechConfigurationException in project motech by motech.
the class DBConfig method validate.
private void validate() {
if (StringUtils.isBlank(getUrl())) {
throw new MotechConfigurationException("Motech DB URL cannot be null or empty.");
}
try {
URL urlObject = new URL(getUrl());
urlObject.toURI();
} catch (MalformedURLException | URISyntaxException e) {
throw new MotechConfigurationException("Motech DB URL is not a valid http URL.", e);
}
}
use of org.motechproject.config.core.exception.MotechConfigurationException in project motech by motech.
the class ConfigPropertiesUtils method createFileIfDoesNotExist.
private static void createFileIfDoesNotExist(String basePath, String fileName) {
File configFile = new File(basePath, fileName);
try {
// These methods create dir/file only if it does not yet exist.
new File(configFile.getParent()).mkdirs();
configFile.createNewFile();
} catch (IOException e) {
throw new MotechConfigurationException(String.format("Cannot create file %s", configFile.getAbsolutePath()), e);
}
}
Aggregations