Java 类io.dropwizard.configuration.ConfigurationException 实例源码

项目:verify-hub    文件:FileBackedConfigDataSource.java   
@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;
}
项目:dropwizard-elasticsearch    文件:ManagedEsClientTest.java   
@Test
public void nodeClientShouldBeCreatedFromConfig() throws URISyntaxException, IOException, ConfigurationException {
    URL configFileUrl = this.getClass().getResource("/node_client.yml");
    File configFile = new File(configFileUrl.toURI());
    EsConfiguration config = configFactory.build(configFile);

    ManagedEsClient managedEsClient = new ManagedEsClient(config);
    Client client = managedEsClient.getClient();

    assertNotNull(client);
    assertTrue(client instanceof NodeClient);

    NodeClient nodeClient = (NodeClient) client;
    assertEquals(config.getClusterName(), nodeClient.settings().get("cluster.name"));
    assertEquals("true", nodeClient.settings().get("node.client"));
    assertEquals("false", nodeClient.settings().get("node.data"));
}
项目:dropwizard-elasticsearch    文件:ManagedEsClientTest.java   
@Test
public void transportClientShouldBeCreatedFromConfig() throws URISyntaxException, IOException, ConfigurationException {
    URL configFileUrl = this.getClass().getResource("/transport_client.yml");
    File configFile = new File(configFileUrl.toURI());
    EsConfiguration config = configFactory.build(configFile);

    ManagedEsClient managedEsClient = new ManagedEsClient(config);
    Client client = managedEsClient.getClient();

    assertNotNull(client);
    assertTrue(client instanceof TransportClient);

    final TransportClient transportClient = (TransportClient) client;
    assertEquals(3, transportClient.transportAddresses().size());
    assertEquals(
            TransportAddressHelper.fromHostAndPort(HostAndPort.fromParts("127.0.0.1", 9300)),
            transportClient.transportAddresses().get(0));
    assertEquals(
            TransportAddressHelper.fromHostAndPort(HostAndPort.fromParts("127.0.0.1", 9301)),
            transportClient.transportAddresses().get(1));
    assertEquals(
            TransportAddressHelper.fromHostAndPort(HostAndPort.fromParts("127.0.0.1", 9302)),
            transportClient.transportAddresses().get(2));
}
项目:dropwizard-elasticsearch    文件:ManagedEsClientTest.java   
@Test
public void managedClientShouldUseCustomElasticsearchConfig() throws URISyntaxException, IOException, ConfigurationException {
    URL configFileUrl = this.getClass().getResource("/custom_settings_file.yml");
    File configFile = new File(configFileUrl.toURI());
    EsConfiguration config = configFactory.build(configFile);

    ManagedEsClient managedEsClient = new ManagedEsClient(config);
    Client client = managedEsClient.getClient();

    assertNotNull(client);
    assertTrue(client instanceof NodeClient);

    NodeClient nodeClient = (NodeClient) client;
    assertEquals(config.getClusterName(), nodeClient.settings().get("cluster.name"));
    assertEquals("19300-19400", nodeClient.settings().get("transport.tcp.port"));
}
项目:dropwizard-elasticsearch    文件:ManagedEsClientTest.java   
@Test
public void managedClientObeysPrecedenceOfSettings() throws URISyntaxException, IOException, ConfigurationException {
    URL configFileUrl = this.getClass().getResource("/custom_settings_precedence.yml");
    File configFile = new File(configFileUrl.toURI());
    EsConfiguration config = configFactory.build(configFile);

    ManagedEsClient managedEsClient = new ManagedEsClient(config);
    Client client = managedEsClient.getClient();

    assertNotNull(client);
    assertTrue(client instanceof NodeClient);

    NodeClient nodeClient = (NodeClient) client;
    assertEquals(config.getClusterName(), nodeClient.settings().get("cluster.name"));
    assertEquals("29300-29400", nodeClient.settings().get("transport.tcp.port"));
    assertEquals("target/data/yaml", nodeClient.settings().get("path.home"));
}
项目:dropwizard-tinkerpop    文件:TinkerPopFactoryTest.java   
private void connect() throws URISyntaxException, IOException, ConfigurationException {
    final File yml = new File(Resources.getResource(serializer).toURI());
    final YamlConfigurationFactory<TinkerPopFactory> factory =
            new YamlConfigurationFactory<>(TinkerPopFactory.class, validator, objectMapper, "dw");
    final Cluster cluster = factory.build(yml).build();
    final Graph graph = EmptyGraph.instance();
    client = cluster.connect();
    g = graph.traversal().withRemote(DriverRemoteConnection.using(cluster, "g"));
}
项目:dropwizard-tinkerpop    文件:TinkerPopFactoryTest.java   
@Test
public void testReadWriteClient() throws ConfigurationException, IOException, URISyntaxException {
    final Long expected = client.submit("g.addV('Person').id()").one().getLong();
    final Long person = client.submit("g.V().hasLabel('Person').id()").one().getLong();
    assertEquals(expected, person);

    if(testBytecode) {
        client.submit("g.V().drop()");
        final Long remoteExpected = (Long) g.addV("Person").id().next();
        final Long remotePerson = (Long) g.V().hasLabel("Person").id().next();
        assertEquals(remoteExpected, remotePerson);
    }
}
项目:verify-hub    文件:SupportedMsaVersionsLoader.java   
public SupportedMsaVersions loadSupportedMsaVersions(final URL url) {
    final ConfigurationFactory<SupportedMsaVersions> factory = supportedMsaVersionsFactoryFactory.create(
            SupportedMsaVersions.class,
            buildDefaultValidatorFactory().getValidator(),
            objectMapper,
            "");
    try {
        SupportedMsaVersions supportedMsaVersions = factory.build(
                configurationSourceProvider,
                url.toString());
        return supportedMsaVersions;
    } catch (IOException | ConfigurationException e) {
        throw propagate(e);
    }
}
项目:dropwizard-hikaricp-benchmark    文件:HikariDataSourceFactoryTest.java   
@Test
public void canDeserializeCorrectly() throws IOException, ConfigurationException {
    final HikariDataSourceFactory factory = new YamlConfigurationFactory<>(HikariDataSourceFactory.class,
            BaseValidator.newValidator(), Jackson.newObjectMapper(), "dw")
            .build(new ResourceConfigurationSourceProvider(), "config.yaml");

    assertThat(factory.getUser()).isEqualTo("nick");
    assertThat(factory.getPassword()).isEqualTo("nickss");
    assertThat(factory.getDatasourceClassName()).isEqualTo("org.postgresql.ds.PGSimpleDataSource");
    assertThat(factory.getProperties()).containsExactly(entry("databaseName", "postgres"));
    assertThat(factory.getMinSize()).isEqualTo(OptionalInt.empty());
    assertThat(factory.getMaxSize()).isEqualTo(12);
    assertThat(factory.isAutoCommit()).isTrue();
}
项目:emodb    文件:EmoService.java   
private EmoConfiguration loadConfigFile(File configFile)
        throws IOException, ConfigurationException {
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory());
    ConfigurationFactory<EmoConfiguration> configurationFactory = new ConfigurationFactory(EmoConfiguration.class, validator, mapper, "dw");
    return configurationFactory.build(configFile);
}
项目:emodb    文件:CreateKeyspacesCommand.java   
public static DdlConfiguration parseDdlConfiguration(File file) throws IOException, ConfigurationException {
    // Similar to Dropwizard's ConfigurationFactory but ignores System property overrides.
    ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory());
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
    DdlConfiguration ddlConfiguration = mapper.readValue(file, DdlConfiguration.class);

    Set<ConstraintViolation<DdlConfiguration>> errors = _validator.validate(ddlConfiguration);
    if (!errors.isEmpty()) {
        throw new ConfigurationValidationException(file.toString(), errors);
    }

    return ddlConfiguration;
}
项目:emodb    文件:SdkConfigTest.java   
@Test
public void ensureSdkDefaultConfigDeserialization()
        throws IOException, URISyntaxException, ConfigurationException {
    // This test makes sure that we haven't forgotten to update the emodb sdk default config file when we add/remove properties
    Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    ObjectMapper mapper = CustomJsonObjectMapperFactory.build(new YAMLFactory());
    ConfigurationFactory configurationFactory = new ConfigurationFactory(EmoConfiguration.class, validator, mapper, "dw");
    // Make sure that our config files are up to date
    configurationFactory.build(
    new File(EmoStartMojo.class.getResource("/emodb-default-config.yaml").toURI()));
}
项目:auth    文件:ConfigurationParser.java   
/**
 * Parses the given configuration file and returns a configuration object.
 *
 * @param configurationFileName The name of the configuration file.
 * @return A configuration object.
 * @throws IOException The IO error that contains detail information.
 * @throws ConfigurationException The configuration error that contains detail information.
 */
public static ApiConfiguration parse(String configurationFileName)
  throws IOException, ConfigurationException {
  if (StringUtils.isBlank(configurationFileName)) {
    throw new IllegalArgumentException("Configuration file cannot be blank");
  }

  ObjectMapper objectMapper = null;
  if (configurationFileName.endsWith("yml") || configurationFileName.endsWith("yaml")) {
    objectMapper = Jackson.newObjectMapper(new YAMLFactory());
  } else if (configurationFileName.endsWith("json")) {
    objectMapper = Jackson.newObjectMapper(new JsonFactory());
  } else {
    throw new IllegalArgumentException("Unrecognized configuration file type");
  }

  ValidatorFactory validatorFactory = Validation
      .byProvider(HibernateValidator.class)
      .configure()
      .addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
      .buildValidatorFactory();

  final ConfigurationFactory<ApiConfiguration> configurationFactory =
      new DefaultConfigurationFactoryFactory<ApiConfiguration>()
        .create(ApiConfiguration.class, validatorFactory.getValidator(), objectMapper, "dw");

  final File file = new File(configurationFileName);
  if (!file.exists()) {
    throw new FileNotFoundException("Configuration file " + configurationFileName + " not found");
  }

  return configurationFactory.build(file);
}
项目:keywhiz    文件:KeywhizTestRunner.java   
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;
}
项目:backups    文件:ConfigurationTestUtil.java   
public static BackupConfiguration loadConfiguration() throws IOException, ConfigurationException {
    if (!CONFIGURATION_FILE.isPresent()) {
        throw new FileNotFoundException(String.format("Unable to find %s", CONFIGURATION_FILENAME));
    }

    return CONFIGURATION_FACTORY.build(CONFIGURATION_FILE.get());
}
项目:backups    文件:BackupConfigurationTest.java   
@Test
public void testTemplateConfigurationIsValid() throws IOException, ConfigurationException {
    final BackupConfiguration config = ConfigurationTestUtil.loadConfiguration();
    assertNotNull(config);

    final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
    assertTrue(validator.validate(config).isEmpty());
}
项目:dropwizard-raven    文件:RavenAppenderFactoryTest.java   
@Test
public void hasValidDefaults() throws IOException, ConfigurationException {
  final RavenAppenderFactory factory = new RavenAppenderFactory();

  assertNull("default dsn is unset", factory.getDsn());
  assertFalse("default environment is empty", factory.getEnvironment().isPresent());
  assertFalse("default extraTags is empty", factory.getEnvironment().isPresent());
  assertFalse("default ravenFactory is empty", factory.getRavenFactory().isPresent());
  assertFalse("default release is empty", factory.getRelease().isPresent());
  assertFalse("default serverName is empty", factory.getServerName().isPresent());
  assertFalse("default tags are empty", factory.getTags().isPresent());
}
项目:dropwizard-environment-config    文件:EnvironmentConfigurationFactoryTest.java   
@Test
public void can_set_variable_with_default_in_array() throws IOException, ConfigurationException {
    environmentProvider.put("ARRAY_2", "5");

    TestConfiguration testConfiguration = environmentConfigurationFactory.build(new File(
            "src/test/resources/config.yaml"));

    assertThat(testConfiguration.array.get(2), is(equalTo("5")));
}
项目:dropwizard-environment-config    文件:EnvironmentConfigurationFactoryTest.java   
@Test
public void can_set_variable_with_default_in_object() throws IOException, ConfigurationException {
    environmentProvider.put("OBJECT_C", "5");

    TestConfiguration testConfiguration = environmentConfigurationFactory.build(new File(
            "src/test/resources/config.yaml"));

    assertThat(testConfiguration.object.get("c"), is(equalTo("5")));
}
项目:dropwizard-environment-config    文件:EnvironmentConfigurationFactoryTest.java   
@Test
public void can_set_variable_without_default_in_array() throws IOException, ConfigurationException {
    environmentProvider.put("ARRAY_1", "5");

    TestConfiguration testConfiguration = environmentConfigurationFactory.build(new File(
            "src/test/resources/config.yaml"));

    assertThat(testConfiguration.array.get(1), is(equalTo("5")));
}
项目:dropwizard-environment-config    文件:EnvironmentConfigurationFactoryTest.java   
@Test
public void can_set_variable_without_default_in_object() throws IOException, ConfigurationException {
    environmentProvider.put("OBJECT_B", "5");

    TestConfiguration testConfiguration = environmentConfigurationFactory.build(new File(
            "src/test/resources/config.yaml"));

    assertThat(testConfiguration.object.get("b"), is(equalTo("5")));
}
项目:dropwizard-environment-config    文件:EnvironmentConfigurationFactoryTest.java   
@Test
public void uses_default_value_in_array() throws IOException, ConfigurationException {
    TestConfiguration testConfiguration = environmentConfigurationFactory.build(new File(
            "src/test/resources/config.yaml"));

    assertThat(testConfiguration.array.get(2), is(equalTo("default")));
}
项目:dropwizard-environment-config    文件:EnvironmentConfigurationFactoryTest.java   
@Test
public void uses_default_value_in_object() throws IOException, ConfigurationException {
    TestConfiguration testConfiguration = environmentConfigurationFactory.build(new File(
            "src/test/resources/config.yaml"));

    assertThat(testConfiguration.object.get("c"), is(equalTo("default")));
}
项目:dropwizard-environment-config    文件:EnvironmentConfigurationFactorySubObjectTest.java   
@Test
public void can_set_variable_with_default_in_array() throws IOException, ConfigurationException {
    environmentProvider.put("SUB_ARRAY_2", "5");

    TestConfiguration testConfiguration = environmentConfigurationFactory.build(new File(
            "src/test/resources/config.yaml"));

    assertThat(testConfiguration.subTestConfiguration.array.get(2), is(equalTo("5")));
}
项目:dropwizard-environment-config    文件:EnvironmentConfigurationFactorySubObjectTest.java   
@Test
public void can_set_variable_with_default_in_object() throws IOException, ConfigurationException {
    environmentProvider.put("SUB_OBJECT_C", "5");

    TestConfiguration testConfiguration = environmentConfigurationFactory.build(new File(
            "src/test/resources/config.yaml"));

    assertThat(testConfiguration.subTestConfiguration.object.get("c"), is(equalTo("5")));
}
项目:dropwizard-environment-config    文件:EnvironmentConfigurationFactorySubObjectTest.java   
@Test
public void can_set_variable_without_default_in_array() throws IOException, ConfigurationException {
    environmentProvider.put("SUB_ARRAY_1", "5");

    TestConfiguration testConfiguration = environmentConfigurationFactory.build(new File(
            "src/test/resources/config.yaml"));

    assertThat(testConfiguration.subTestConfiguration.array.get(1), is(equalTo("5")));
}
项目:dropwizard-environment-config    文件:EnvironmentConfigurationFactorySubObjectTest.java   
@Test
public void can_set_variable_without_default_in_object() throws IOException, ConfigurationException {
    environmentProvider.put("SUB_OBJECT_B", "5");

    TestConfiguration testConfiguration = environmentConfigurationFactory.build(new File(
            "src/test/resources/config.yaml"));

    assertThat(testConfiguration.subTestConfiguration.object.get("b"), is(equalTo("5")));
}
项目:dropwizard-environment-config    文件:EnvironmentConfigurationFactorySubObjectTest.java   
@Test
public void uses_default_value_in_array() throws IOException, ConfigurationException {
    TestConfiguration testConfiguration = environmentConfigurationFactory.build(new File(
            "src/test/resources/config.yaml"));

    assertThat(testConfiguration.subTestConfiguration.array.get(2), is(equalTo("default")));
}
项目:dropwizard-environment-config    文件:EnvironmentConfigurationFactorySubObjectTest.java   
@Test
public void uses_default_value_in_object() throws IOException, ConfigurationException {
    TestConfiguration testConfiguration = environmentConfigurationFactory.build(new File(
            "src/test/resources/config.yaml"));

    assertThat(testConfiguration.subTestConfiguration.object.get("c"), is(equalTo("default")));
}
项目:dropwizard-tinkerpop    文件:TinkerPopFactoryTest.java   
@Before
public void setUp() throws URISyntaxException, IOException, ConfigurationException {
    connect();
}
项目:AugumentedSzczecin_java    文件:OpenDataClientConfiguration.java   
public String getUrl() throws ConfigurationException {
    return url;
}
项目:AugumentedSzczecin_java    文件:OpenDataClientModule.java   
@Singleton
@Provides
@Named("openDataUrl")
public String provideOpenDataClient(final OpenDataClientConfiguration configuration) throws ConfigurationException {
    return configuration.getUrl();
}
项目:backups    文件:AzureBackupProcessorTest.java   
@Override
protected AzureTableMetadataStorage<BackupMetadata> getMetadataStorage() throws IOException, ConfigurationException {
    return new AzureTableMetadataStorage<>(BackupMetadata.class, configuration, azureNamespace, new MetricRegistry());
}
项目:backups    文件:AzurelikeBackupProcessorTest.java   
@Override
protected AzureTablelikeMetadataStorage<BackupMetadata> getMetadataStorage() throws IOException, ConfigurationException {
    return new AzureTablelikeMetadataStorage<>(BackupMetadata.class);
}
项目:backups    文件:TemporaryTokenGeneratorTest.java   
@Before
public void setUp() throws InvalidKeySpecException, NoSuchAlgorithmException, IOException, ConfigurationException {
    final TokenConfiguration config = ConfigurationTestUtil.loadConfiguration().getTokenConfiguration();
    generator = new TemporaryTokenGenerator(config);
}
项目:backups    文件:AzureTableMetadataStorageTest.java   
@Override
protected MetadataStorage<BackupMetadata> getMetadataStorage() throws IOException, ConfigurationException {
    final BackupConfiguration configuration = ConfigurationTestUtil.loadConfiguration();
    return new AzureTableMetadataStorage<>(BackupMetadata.class, configuration.getOffsiteConfiguration().getStorageConfiguration(), azureNamespace, new MetricRegistry());
}
项目:backups    文件:AzureFileStorageTest.java   
@Override
protected AzureFileStorage getFileStorage() throws IOException, ConfigurationException, StorageException, InvalidKeyException, URISyntaxException {
    final BackupConfiguration configuration = ConfigurationTestUtil.loadConfiguration();
    return new AzureFileStorage(configuration.getOffsiteConfiguration().getStorageConfiguration(), azureNamespace);
}
项目:dropwizard-elasticsearch    文件:EsConfigurationTest.java   
@Test
public void defaultConfigShouldBeValid() throws IOException, ConfigurationException {
    configFactory.build();
}
项目:dropwizard-elasticsearch    文件:EsConfigurationTest.java   
@Test(expected = ConfigurationException.class)
public void eitherNodeClientOrServerListMustBeSet() throws IOException, ConfigurationException, URISyntaxException {
    URL configFileUrl = this.getClass().getResource("/invalid.yml");
    File configFile = new File(configFileUrl.toURI());
    configFactory.build(configFile);
}
项目:dropwizard-config-importable    文件:ImportableConfigurationFactory.java   
/**
 * Loads, parses, binds, and validates a configuration object.
 *
 * @param provider the provider to to use for reading configuration files
 * @param path     the path of the configuration file
 * @return a validated configuration object
 * @throws IOException            if there is an error reading the file
 * @throws ConfigurationException if there is an error parsing or validating the file
 */
public T build(ConfigurationSourceProvider provider, String path)
    throws IOException, ConfigurationException
{
    return build(loadConfiguration(provider, path), path);
}