dropwizard测试集成给出一个异常ConfigurationParsingException

时间:2015-12-29 10:41:30

标签: java mongodb jetty yaml dropwizard

我目前正在与framwork dropwizard,embeddedmongo进行集成测试。但是当我执行测试时,我总是这个例外。

com.example.pointypatient.integration.PointyPatientApplicationTest  Time elapsed: 3.054 sec  <<< ERROR!
java.lang.RuntimeException: io.dropwizard.configuration.ConfigurationParsingException: dropwizard-angular- example-master\target\test-classes\integration.yml has an error:Configuration at dropwizard-angular-example-master\target\test-classes\integration.yml must not be empty

我的integration.yml就在这里:

dbConfig:
  host: localhost
  port: 12345
  dbName: test

server:
  applicationConnectors:
    - type: http
      port: 8080
    - type: https
      port: 8443
      keyStorePath: example.keystore
      keyStorePassword: example
      validateCerts: false
  adminConnectors:
    - type: http
      port: 8081
    - type: https
      port: 8444
      keyStorePath: example.keystore
      keyStorePassword: example
      validateCerts: false

# Logging settings.
logging:
  # The default level of all loggers. Can be OFF, ERROR, WARN, INFO, DEBUG, TRACE, or ALL.
  level: INFO

  appenders:
    - type: console

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

ConfigurationFactory.java开始,仅当readTree的方法ObjectMapper返回null时才会抛出此异常。

  • 查看您传递给ConfigurationSourceProvider方法的build派生类,因为它没有正确处理IOException(我可以假设您使用的是模拟的);
  • 看看path参数,看来你应该传递“dropwizard-angular- example-master \ target \ test-classes \ integration.yml”而不是“ dropwizard-angular-example-master \ target \ test-classes \ integration.yml“ *第一个路径在 dropwizard-angular -
  • 之后有一个空格

答案 1 :(得分:0)

如果您的 dropwizard-config 文件(即 integration.yml)在 test/resources 目录中,您不需要使用 ResourceHelpers.resourceFilePath("integration.yml") 将完整的配置路径传递到 DropwizardAppExtension 作为一个参数,你应该只传递它的名字(例如“integration.yml”)

private static DropwizardAppExtension<MyDropwizardConfiguration> RULE = new DropwizardAppExtension<>(
            MyDropwizardApplication.class, "integration.yml");