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

项目:trellis-rosid    文件:TrellisUtilsTest.java   
@Test
public void testGetAuthFilters() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    final Optional<List<AuthFilter>> filters = TrellisUtils.getAuthFilters(config);
    assertTrue(filters.isPresent());
    filters.ifPresent(f -> assertEquals(3L, f.size()));

    config.getAuth().getAnon().setEnabled(false);
    config.getAuth().getBasic().setEnabled(false);
    config.getAuth().getJwt().setEnabled(false);

    assertFalse(TrellisUtils.getAuthFilters(config).isPresent());
}
项目:trellis-rosid    文件:TrellisConfigurationTest.java   
@Test
public void testConfigurationAuth1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getAuth().getWebac().getEnabled());
    assertEquals((Long) 100L, config.getAuth().getWebac().getCacheSize());
    assertEquals((Long) 10L, config.getAuth().getWebac().getCacheExpireSeconds());
    assertTrue(config.getAuth().getAnon().getEnabled());
    assertTrue(config.getAuth().getBasic().getEnabled());
    assertEquals("users.auth", config.getAuth().getBasic().getUsersFile());
    assertTrue(config.getAuth().getJwt().getEnabled());
    assertEquals("secret", config.getAuth().getJwt().getKey());
    assertFalse(config.getAuth().getJwt().getBase64Encoded());
}
项目: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-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();
}
项目:trellis-rosid    文件:TrellisUtilsTest.java   
@Test
public void testGetAssetConfigurations() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    final Map<String, String> assets = TrellisUtils.getAssetConfiguration(config);
    assertEquals(3L, assets.size());
    assertEquals("http://example.org/image.icon", assets.get("icon"));
    assertEquals("http://example.org/styles1.css,http://example.org/styles2.css",
            assets.get("css"));
    assertEquals("http://example.org/scripts1.js,http://example.org/scripts2.js",
            assets.get("js"));
}
项目:trellis-rosid    文件:TrellisUtilsTest.java   
@Test
public void testGetKafkaProperties() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    final Properties props = TrellisUtils.getKafkaProperties(config);

    assertEquals("org.apache.kafka.common.serialization.StringSerializer", props.getProperty("key.serializer"));
    assertEquals("org.apache.kafka.common.serialization.StringSerializer", props.getProperty("value.serializer"));
    assertEquals("localhost:9092", props.getProperty("bootstrap.servers"));
}
项目:trellis-rosid    文件:TrellisUtilsTest.java   
@Test
public void testGetCurator() throws Exception {
    final TestingServer zk = new TestingServer(true);

    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    config.getZookeeper().setEnsembleServers(zk.getConnectString());

    final CuratorFramework curator = TrellisUtils.getCuratorClient(config);
    assertEquals(CuratorFrameworkState.STARTED, curator.getState());
}
项目:trellis-rosid    文件:TrellisConfigurationTest.java   
@Test
public void testConfigurationGeneral1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getAsync());
    assertEquals("Trellis", config.getDefaultName());
    assertEquals((Integer) 86400, config.getCacheMaxAge());
    assertEquals((Long) 100L, config.getJsonLdCacheSize());
    assertEquals((Long) 24L, config.getJsonLdCacheExpireHours());
    assertTrue(config.getJsonLdDomainWhitelist().isEmpty());
    assertTrue(config.getJsonLdWhitelist().contains("http://example.org/context.json"));
}
项目:trellis-rosid    文件:TrellisConfigurationTest.java   
@Test
public void testConfigurationAssets1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("http://example.org/image.icon", config.getAssets().getIcon());
    assertTrue(config.getAssets().getJs().contains("http://example.org/scripts1.js"));
    assertTrue(config.getAssets().getCss().contains("http://example.org/styles1.css"));
}
项目:trellis-rosid    文件:TrellisConfigurationTest.java   
@Test
public void testConfigurationLocations() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("/tmp/trellisData/binaries", config.getBinaries().getPath());
    assertEquals("/tmp/trellisData/resources", config.getResources().getPath());
    assertEquals("http://localhost:8080/", config.getBaseUrl());
    assertEquals((Integer) 4, config.getBinaries().getLevels());
    assertEquals((Integer) 2, config.getBinaries().getLength());
}
项目:trellis-rosid    文件:TrellisConfigurationTest.java   
@Test
public void testConfigurationNamespaces1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("/tmp/trellisData/namespaces.json", config.getNamespaces().getFile());
}
项目:trellis-rosid    文件:TrellisConfigurationTest.java   
@Test
public void testConfigurationCORS1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertTrue(config.getCors().getEnabled());
    assertTrue(config.getCors().getAllowOrigin().contains("*"));
    assertTrue(config.getCors().getAllowHeaders().contains("Link"));
    assertTrue(config.getCors().getAllowMethods().contains("PATCH"));
    assertTrue(config.getCors().getExposeHeaders().contains("Location"));
    assertEquals((Integer) 180, config.getCors().getMaxAge());
    assertTrue(config.getCors().getAllowCredentials());
}
项目:trellis-rosid    文件:TrellisConfigurationTest.java   
@Test
public void testConfigurationZookeeper1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("localhost:2181", config.getZookeeper().getEnsembleServers());
    assertEquals((Integer) 100, config.getZookeeper().getTimeout());
    assertEquals((Integer) 1000, config.getZookeeper().getRetryMs());
    assertEquals((Integer) 10, config.getZookeeper().getRetryMax());
    assertEquals((Integer) 50, config.getZookeeper().getRetryMaxMs());
}
项目:trellis-rosid    文件:TrellisConfigurationTest.java   
@Test
public void testConfigurationKafka1() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));

    assertEquals("localhost:9092", config.getKafka().getBootstrapServers());

    final Properties props = config.getKafka().asProperties();
    assertEquals("all", props.getProperty("acks"));
    assertEquals("16384", props.getProperty("batch.size"));
    assertEquals("otherValue", props.getProperty("otherProperty"));
}
项目:dropwizard-pac4j    文件:AbstractConfigurationTest.java   
protected Pac4jFactory getPac4jFactory(
        Collection<Pac4jFeatureSupport> featuresSupported,
        String resourceName) throws Exception {
    ObjectMapper om = Jackson.newObjectMapper();
    Bootstrap<?> b = mock(Bootstrap.class);
    when(b.getObjectMapper()).thenReturn(om);

    for (Pac4jFeatureSupport fs : featuresSupported) {
        fs.setup(b);
    }

    return new YamlConfigurationFactory<>(Pac4jFactory.class,
            Validators.newValidator(), om, "dw").build(
                    new File(Resources.getResource(resourceName).toURI()));
}
项目:dropwizard-http2-client    文件:JettyClientConfigurationTest.java   
private JettyClientConfiguration load(String configLocation) {
    try {
        return new YamlConfigurationFactory<>(JettyClientConfiguration.class,
                Validators.newValidator(),
                Jackson.newObjectMapper(), "dw-http-client")
                .build(new File(Resources.getResource(configLocation).toURI()));
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
}
项目:soabase    文件:AdminConsoleAppBuilder.java   
public AdminConsoleAppBuilder<T> withConfigurationClass(final Class<T> configurationClass)
{
    factoryFactory = new ConfigurationFactoryFactory<T>()
    {
        @Override
        public ConfigurationFactory<T> create(Class<T> klass, Validator validator, ObjectMapper objectMapper, String propertyPrefix)
        {
            return new YamlConfigurationFactory<>(configurationClass, validator, objectMapper, propertyPrefix);
        }
    };
    return this;
}
项目:breakerbox    文件:YamlInstanceDiscovery.java   
public YamlInstanceDiscovery(Path path,
                             Validator validator,
                             ObjectMapper objectMapper) {
    this.path = path;
    this.configurationFactory = new YamlConfigurationFactory<>(
            YamlInstanceConfiguration.class,
            validator,
            objectMapper,
            "dw");
    parseYamlInstanceConfiguration();
}
项目:breakerbox    文件:WithConfiguration.java   
@Before
public void setupTest() throws Exception {
    azureTableConfiguration = new YamlConfigurationFactory<>(
            AzureTableConfiguration.class,
            Validation.buildDefaultValidatorFactory().getValidator(),
            Jackson.newObjectMapper(),
            "dw.").build(new File(Resources.getResource("azure-test.yml").toURI()));
}
项目:haystack-client-java    文件:BaseFactoryTest.java   
protected T testFactory(YamlConfigurationFactory<T> factory, String yamlFile, Class clazz) throws Exception {
    final File yml = new File(Resources.getResource(yamlFile).toURI());
    T t = factory.build(yml);
    assertThat(t).isInstanceOf(clazz);
    return t;
}
项目:trellis-rosid    文件:TrellisUtilsTest.java   
@Test
public void testGetWebacConfig() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));


    assertTrue(TrellisUtils.getWebacConfiguration(config).isPresent());

    config.getAuth().getWebac().setEnabled(false);

    assertFalse(TrellisUtils.getWebacConfiguration(config).isPresent());
}
项目:trellis-rosid    文件:TrellisUtilsTest.java   
@Test
public void testGetCORSConfig() throws Exception {
    final TrellisConfiguration config = new YamlConfigurationFactory<>(TrellisConfiguration.class,
            Validators.newValidator(), Jackson.newObjectMapper(), "")
        .build(new File(getClass().getResource("/config1.yml").toURI()));


    assertTrue(TrellisUtils.getCorsConfiguration(config).isPresent());

    config.getCors().setEnabled(false);

    assertFalse(TrellisUtils.getCorsConfiguration(config).isPresent());
}