@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()); }
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")); }
@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(); }
@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())); }
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); } }
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; }
public YamlInstanceDiscovery(Path path, Validator validator, ObjectMapper objectMapper) { this.path = path; this.configurationFactory = new YamlConfigurationFactory<>( YamlInstanceConfiguration.class, validator, objectMapper, "dw"); parseYamlInstanceConfiguration(); }
@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())); }
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; }
@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()); }