Search in sources :

Example 6 with Bootstrap

use of io.dropwizard.setup.Bootstrap 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;
}
Also used : IOException(java.io.IOException) ConfigurationException(io.dropwizard.configuration.ConfigurationException) Injector(com.google.inject.Injector) ConfigurationFactory(io.dropwizard.configuration.ConfigurationFactory) Bootstrap(io.dropwizard.setup.Bootstrap) Environment(io.dropwizard.setup.Environment) File(java.io.File) Validator(javax.validation.Validator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with Bootstrap

use of io.dropwizard.setup.Bootstrap in project dropwizard by dropwizard.

the class CommandTest method setUp.

@BeforeEach
void setUp() {
    final JarLocation location = mock(JarLocation.class);
    final Bootstrap<Configuration> bootstrap = new Bootstrap<>(app);
    when(location.toString()).thenReturn("dw-thing.jar");
    when(location.getVersion()).thenReturn(Optional.of("1.0.0"));
    bootstrap.addCommand(command);
    cli = new Cli(location, bootstrap, stdOut, stdErr);
}
Also used : JarLocation(io.dropwizard.util.JarLocation) Configuration(io.dropwizard.Configuration) Bootstrap(io.dropwizard.setup.Bootstrap) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with Bootstrap

use of io.dropwizard.setup.Bootstrap in project keywhiz by square.

the class EnvironmentsTest method createsEnvironmentFromBootstrap.

@Test
public void createsEnvironmentFromBootstrap() {
    KeywhizService keywhiz = new KeywhizService();
    Bootstrap<KeywhizConfig> bootstrap = new Bootstrap<>(keywhiz);
    Environment environment = Environments.fromBootstrap(bootstrap);
    assertEquals(keywhiz.getName(), environment.getName());
    assertNotSame(bootstrap.getObjectMapper(), environment.getObjectMapper());
    assertNotNull(environment.getValidator());
    assertSame(bootstrap.getMetricRegistry(), environment.metrics());
    assertSame(bootstrap.getClassLoader(), environment.getAdminContext().getClassLoader());
}
Also used : Bootstrap(io.dropwizard.setup.Bootstrap) Environment(io.dropwizard.setup.Environment) Test(org.junit.Test)

Aggregations

Bootstrap (io.dropwizard.setup.Bootstrap)8 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Environment (io.dropwizard.setup.Environment)4 Configuration (io.dropwizard.Configuration)3 JarLocation (io.dropwizard.util.JarLocation)3 ConfigurationFactory (io.dropwizard.configuration.ConfigurationFactory)2 ConfigurationSourceProvider (io.dropwizard.configuration.ConfigurationSourceProvider)2 Validator (javax.validation.Validator)2 Namespace (net.sourceforge.argparse4j.inf.Namespace)2 Injector (com.google.inject.Injector)1 Application (io.dropwizard.Application)1 Cli (io.dropwizard.cli.Cli)1 Command (io.dropwizard.cli.Command)1 ConfiguredCommand (io.dropwizard.cli.ConfiguredCommand)1 EnvironmentCommand (io.dropwizard.cli.EnvironmentCommand)1 ServerCommand (io.dropwizard.cli.ServerCommand)1 ConfigurationException (io.dropwizard.configuration.ConfigurationException)1 YamlConfigurationFactory (io.dropwizard.configuration.YamlConfigurationFactory)1 Managed (io.dropwizard.lifecycle.Managed)1 LoggingFactory (io.dropwizard.logging.LoggingFactory)1