@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()); }
@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()); }
@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(); } }
@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")); }
@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")); }
@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()); }
@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")); }
@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")); }
@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()); }
@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()); }
@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()); }
@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()); }
@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")); }
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())); }
@Override public void run(Environment environment) { environment.setValidator(Validators .newConfiguration() .constraintValidatorFactory(new InjectingValidatorFactory()) .buildValidatorFactory() .getValidator()); }
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); } }
@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); }
@BeforeClass public static void setupTest() throws Exception { PluginsFactory.setInstanceDiscovery(new YamlInstanceDiscovery( Paths.get(Resources.getResource("turbineConfigurations/instances.yml").toURI()), Validators.newValidator(), Jackson.newObjectMapper())); }
@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); }
/** * 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()); }
@Override protected void configureClient(final ClientConfig config) { config.register(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), Validators.newValidator())); }
@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()); }
@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()); }