use of io.dropwizard.configuration.ConfigurationException in project dropwizard by dropwizard.
the class InheritedServerCommandTest method usesDefaultConfigPath.
@Test
public void usesDefaultConfigPath() throws Exception {
class SingletonConfigurationFactory implements ConfigurationFactory {
@Override
public Object build(final ConfigurationSourceProvider provider, final String path) throws IOException, ConfigurationException {
return configuration;
}
@Override
public Object build() throws IOException, ConfigurationException {
throw new AssertionError("Didn't use the default config path variable");
}
}
when(configuration.getLoggingFactory()).thenReturn(mock(LoggingFactory.class));
final Bootstrap<Configuration> bootstrap = new Bootstrap<>(application);
bootstrap.setConfigurationFactoryFactory((klass, validator, objectMapper, propertyPrefix) -> new SingletonConfigurationFactory());
bootstrap.addCommand(new ConfiguredCommand<Configuration>("test", "a test command") {
@Override
protected void run(final Bootstrap<Configuration> bootstrap, final Namespace namespace, final Configuration configuration) throws Exception {
assertThat(namespace.getString("file")).isNotEmpty().isEqualTo("yaml/server.yml");
}
@Override
protected Argument addFileArgument(final Subparser subparser) {
return super.addFileArgument(subparser).setDefault("yaml/server.yml");
}
});
final JarLocation location = mock(JarLocation.class);
when(location.toString()).thenReturn("dw-thing.jar");
when(location.getVersion()).thenReturn(Optional.of("1.0.0"));
Cli cli = new Cli(location, bootstrap, System.out, System.err);
cli.run("test");
}
use of io.dropwizard.configuration.ConfigurationException in project verify-hub by alphagov.
the class FileBackedConfigDataSource method loadConfig.
@Override
public Collection<T> loadConfig() {
Collection<T> configData = new ArrayList<>();
final File configDirectory = new File(configuration.getDataDirectory(), dataDirectory);
final File[] dataFiles = configDirectory.listFiles((FilenameFilter) new WildcardFileFilter("*.yml"));
if (dataFiles == null) {
throw ConfigValidationException.createFileReadError(configDirectory.getAbsolutePath());
}
for (File dataFile : dataFiles) {
T data;
try {
data = configurationFactory.build(dataFile);
} catch (IOException | ConfigurationException e) {
throw Throwables.propagate(e);
}
configData.add(data);
}
return configData;
}
use of io.dropwizard.configuration.ConfigurationException in project keywhiz by square.
the class KeywhizTestRunner method createInjector.
static Injector createInjector() {
KeywhizService service = new KeywhizService();
Bootstrap<KeywhizConfig> bootstrap = new Bootstrap<>(service);
service.initialize(bootstrap);
File yamlFile = new File(Resources.getResource("keywhiz-test.yaml").getFile());
Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
ObjectMapper objectMapper = bootstrap.getObjectMapper().copy();
KeywhizConfig config;
try {
config = new ConfigurationFactory<>(KeywhizConfig.class, validator, objectMapper, "dw").build(yamlFile);
} catch (IOException | ConfigurationException e) {
throw Throwables.propagate(e);
}
Environment environment = new Environment(service.getName(), objectMapper, validator, bootstrap.getMetricRegistry(), bootstrap.getClassLoader());
Injector injector = Guice.createInjector(new ServiceModule(config, environment));
service.setInjector(injector);
return injector;
}
Aggregations