Java 类io.dropwizard.jersey.validation.Validators 实例源码

项目: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-jdbi3    文件:JdbiTest.java   
@Before
public void setUp() throws Exception {
    environment = new Environment("test", new ObjectMapper(), Validators.newValidator(),
            metricRegistry, ClassLoader.getSystemClassLoader());

    DataSourceFactory dataSourceFactory = new DataSourceFactory();
    dataSourceFactory.setUrl("jdbc:h2:mem:jdbi3-test");
    dataSourceFactory.setUser("sa");
    dataSourceFactory.setDriverClass("org.h2.Driver");
    dataSourceFactory.asSingleConnectionPool();

    dbi = new JdbiFactory(new TimedAnnotationNameStrategy()).build(environment, dataSourceFactory, "h2");
    dbi.useTransaction(h -> {
        h.createScript(Resources.toString(Resources.getResource("schema.sql"), Charsets.UTF_8)).execute();
        h.createScript(Resources.toString(Resources.getResource("data.sql"), Charsets.UTF_8)).execute();
    });
    dao = dbi.onDemand(GameDao.class);
    for (LifeCycle lc : environment.lifecycle().getManagedObjects()) {
        lc.start();
    }
}
项目: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-hk2bundle    文件:HK2ValidationBundle.java   
@Override
public void run(Environment environment) {
    environment.setValidator(Validators
            .newConfiguration()
            .constraintValidatorFactory(new InjectingValidatorFactory())
            .buildValidatorFactory()
            .getValidator());
}
项目: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);
    }
}
项目:dropwizard-java8    文件:Java8Bundle.java   
@Override
public void initialize(final Bootstrap<?> bootstrap) {
    bootstrap.getObjectMapper().registerModules(new Jdk8Module());
    bootstrap.getObjectMapper().registerModules(new JavaTimeModule());

    final ValidatorFactory validatorFactory = Validators.newConfiguration()
            .addValidatedValueHandler(new OptionalValidatedValueUnwrapper())
            .buildValidatorFactory();
    bootstrap.setValidatorFactory(validatorFactory);
}
项目:breakerbox    文件:InstancesTest.java   
@BeforeClass
public static void setupTest() throws Exception {
    PluginsFactory.setInstanceDiscovery(new YamlInstanceDiscovery(
            Paths.get(Resources.getResource("turbineConfigurations/instances.yml").toURI()),
            Validators.newValidator(),
            Jackson.newObjectMapper()));
}
项目:breakerbox    文件:SyncComparatorTest.java   
@Before
public void setup() throws Exception {
    PluginsFactory.setInstanceDiscovery(new YamlInstanceDiscovery(
            Paths.get(Resources.getResource("turbineConfigurations/instances.yml").toURI()),
            Validators.newValidator(),
            Jackson.newObjectMapper()));
    mockFactory = mock(TenacityConfigurationFetcher.Factory.class);
    mockTenacityStory = mock(BreakerboxStore.class);
    mockFetcher = mock(TenacityConfigurationFetcher.class);
}
项目:dropwizard-vavr    文件:VavrBundle.java   
/**
 * Creates a new {@link HibernateValidatorConfiguration} with all the custom {@link
 * org.hibernate.validator.spi.valuehandling.ValidatedValueUnwrapper} registered.
 */
private static HibernateValidatorConfiguration newValidatorConfiguration() {
    return Validators.newConfiguration()
            .addValidatedValueHandler(new ValueValidatedValueUnwrapper());
}
项目:CredentialStorageService-dw-hibernate    文件:JerseyIntegrationTest.java   
@Override
protected void configureClient(final ClientConfig config) {
    config.register(new JacksonMessageBodyProvider(Jackson.newObjectMapper(),
            Validators.newValidator()));
}
项目: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());
}