Search in sources :

Example 11 with MotechConfigurationException

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();
}
Also used : MotechConfigurationException(org.motechproject.config.core.exception.MotechConfigurationException) Test(org.junit.Test)

Example 12 with MotechConfigurationException

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();
}
Also used : MotechConfigurationException(org.motechproject.config.core.exception.MotechConfigurationException) Test(org.junit.Test)

Example 13 with MotechConfigurationException

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"));
}
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)

Example 14 with MotechConfigurationException

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);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) MotechConfigurationException(org.motechproject.config.core.exception.MotechConfigurationException) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL)

Example 15 with MotechConfigurationException

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);
    }
}
Also used : IOException(java.io.IOException) MotechConfigurationException(org.motechproject.config.core.exception.MotechConfigurationException) File(java.io.File)

Aggregations

MotechConfigurationException (org.motechproject.config.core.exception.MotechConfigurationException)19 IOException (java.io.IOException)6 Test (org.junit.Test)5 Properties (java.util.Properties)4 ConfigLocation (org.motechproject.config.core.domain.ConfigLocation)4 File (java.io.File)3 URISyntaxException (java.net.URISyntaxException)3 ArrayList (java.util.ArrayList)3 URI (java.net.URI)2 URISupport (org.apache.activemq.util.URISupport)2 URISupport.isCompositeURI (org.apache.activemq.util.URISupport.isCompositeURI)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 BootstrapConfig (org.motechproject.config.core.domain.BootstrapConfig)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Resource (org.springframework.core.io.Resource)2 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 Writer (java.io.Writer)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1