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

项目:Mastering-Mesos    文件:SingularityRunnerConfigurationProvider.java   
@Override
public T get() {
  final Configuration configuration = clazz.getAnnotation(Configuration.class);

  try {
    final File baseFile = new File(configuration.filename());
    final T baseConfig = baseFile.exists() ? objectMapper.readValue(baseFile, clazz) : clazz.newInstance();

    final JsonNode overrideNode = filename.isPresent() ? loadYamlField(filename.get(), configuration.consolidatedField()) : objectMapper.createObjectNode();

    final T config = objectMapper.readerForUpdating(baseConfig).readValue(overrideNode);

    final Set<ConstraintViolation<T>> violations = validator.validate(config);
    if (!violations.isEmpty()) {
      throw new ConfigurationValidationException(filename.or(configuration.filename()), violations);
    }

    return config;
  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
}
项目:Singularity    文件:SingularityRunnerConfigurationProvider.java   
@Override
public T get() {
  final Configuration configuration = clazz.getAnnotation(Configuration.class);

  try {
    final File baseFile = new File(configuration.filename());
    final T baseConfig = baseFile.exists() ? objectMapper.readValue(baseFile, clazz) : clazz.newInstance();

    final JsonNode overrideNode = filename.isPresent() ? loadYamlField(filename.get(), configuration.consolidatedField()) : objectMapper.createObjectNode();

    final T config = objectMapper.readerForUpdating(baseConfig).readValue(overrideNode);

    final Set<ConstraintViolation<T>> violations = validator.validate(config);
    if (!violations.isEmpty()) {
      throw new ConfigurationValidationException(filename.or(configuration.filename()), violations);
    }

    return config;
  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
}
项目: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;
}
项目:dropwizard-auth-example    文件:UserInfoConfigurationTest.java   
@Test(expected = ConfigurationValidationException.class)
public void testThatInvalidConfigurationFailsToBeBuilt() throws Exception {
    buildConfigurationFromString("dropwizard/invalid-conf.yml");
}
项目:dropwizard-auth-example    文件:UserInfoConfigurationTest.java   
@Test(expected = ConfigurationValidationException.class)
public void testThatConfigurationWithEmptyValueFailsToBeBuilt() throws Exception {
    buildConfigurationFromString("dropwizard/empty-conf.yml");
}