use of org.motechproject.config.core.exception.MotechConfigurationException in project motech by motech.
the class BootstrapManagerTest method shouldLoadPropertiesInTheCorrectOrder.
@PrepareForTest(ConfigPropertiesUtils.class)
@Test
public void shouldLoadPropertiesInTheCorrectOrder() throws IOException {
PowerMockito.mockStatic(ConfigPropertiesUtils.class);
Iterable<ConfigLocation> configLocations = new ArrayList<ConfigLocation>();
Properties properties = createProperties();
properties.put(SQL_URL, "");
when(environment.getConfigDir()).thenReturn(null);
when(environment.getBootstrapProperties()).thenReturn(properties);
when(configLocationFileStore.getAll()).thenReturn(configLocations);
when(ConfigPropertiesUtils.getDefaultPropertiesFile(ConfigLocation.FileAccessType.READABLE, configLocations, BootstrapManager.BOOTSTRAP_PROPERTIES)).thenThrow(new MotechConfigurationException("Error loading file from config locations"));
try {
bootstrapManager.loadBootstrapConfig();
} catch (MotechConfigurationException e) {
// Ignore error because invocation order is to be verified.
}
InOrder inOrder = Mockito.inOrder(environment, configLocationFileStore);
inOrder.verify(environment).getConfigDir();
inOrder.verify(environment).getBootstrapProperties();
inOrder.verify(configLocationFileStore).getAll();
}
use of org.motechproject.config.core.exception.MotechConfigurationException in project motech by motech.
the class QueueURLValidator method validateComposite.
private void validateComposite(URI brokerURL, String value) throws URISyntaxException {
URISupport.CompositeData data = parseComposite(brokerURL);
String scheme = data.getScheme();
if (scheme != null && ("failover".equals(scheme) || "fanout".equals(scheme) || "vm".equals(scheme))) {
for (URI uri : data.getComponents()) {
validateUriContainSpecificScheme(brokerURL.toString(), uri);
}
} else if (scheme != null) {
isValidUri(brokerURL.toString(), value);
} else {
throw new MotechConfigurationException(URL_INVALID);
}
}
use of org.motechproject.config.core.exception.MotechConfigurationException in project motech by motech.
the class QueueURLValidator method validate.
/**
* Checks whether given URL is valid.
*
* @param queueUrl the URL to be validated
* @throws MotechConfigurationException if queueUrl is null, empty or invalid
*/
public void validate(String queueUrl) {
if (StringUtils.isBlank(queueUrl)) {
throw new MotechConfigurationException("Queue URL cannot be null or empty.");
}
try {
String value = queueUrl.replace("localhost", "127.0.0.1");
URI brokerURL = new URI(value);
if (isCompositeURI(brokerURL)) {
validateComposite(brokerURL, value);
} else {
isValidUri(queueUrl, value);
}
} catch (URISyntaxException e) {
throw new MotechConfigurationException(URL_INVALID, e);
}
}
use of org.motechproject.config.core.exception.MotechConfigurationException in project motech by motech.
the class ConfigLocationFileStore method save.
private void save(List<String> configLocations) {
try {
propertiesConfiguration.setProperty(CONFIG_LOCATION_PROPERTY_KEY, StringUtils.join(configLocations, ","));
propertiesConfiguration.save();
} catch (ConfigurationException e) {
String errorMessage = String.format("Could not save %s in this location %s.", propertiesConfiguration.getFileName(), propertiesConfiguration.getBasePath());
throw new MotechConfigurationException(errorMessage, e);
}
}
use of org.motechproject.config.core.exception.MotechConfigurationException in project motech by motech.
the class ConfigFileMonitor method init.
/**
* Initializes the configuration file monitor. This method will be automatically called after creation and
* dependency injection. It is done to make sure that injected dependencies are set and ready to use.
*/
@PostConstruct
public void init() throws IOException {
BootstrapConfig bootstrapConfig = configurationService.loadBootstrapConfig();
if (bootstrapConfig != null && bootstrapConfig.getConfigSource() == ConfigSource.FILE) {
// allow custom monitors to be injected
if (fileMonitor == null) {
fileMonitor = new DefaultFileMonitor(this);
// allow raw configs, which are one directory down, under /raw/, to be monitored
fileMonitor.setRecursive(true);
}
fileMonitor.setDelay(DELAY);
final List<File> files = new ArrayList<>();
try {
files.addAll(configLoader.findExistingConfigs());
} catch (MotechConfigurationException ex) {
LOGGER.error(ex.getMessage(), ex);
return;
}
configurationService.processExistingConfigs(files);
startFileMonitor();
}
}
Aggregations