@Test public void testGetConfiguration() { FileBasedConfiguration<ClasspathResource> configuration = ComponentConfigurationManager.getConfiguration("Configuration", "junk", "JUNIT"); Logger.getAnonymousLogger().info(configuration.toString()); FileBasedConfiguration<ClasspathResource> secureConfiguration = ComponentConfigurationManager.getConfiguration("Configuration", "FileShare", "JUNIT"); Logger.getAnonymousLogger().info(secureConfiguration.toString()); // Logger.getAnonymousLogger().info(secureConfiguration.getString("encrypted")); // // Logger.getAnonymousLogger().info("" + secureConfiguration.getProperty("encrypted")); // // Logger.getAnonymousLogger().info("" + // secureConfiguration.getAsProperties().getProperty("encrypted")); // // Logger.getAnonymousLogger().info(secureConfiguration.getString("encrypted")); }
@Test @SneakyThrows public void testCombinedClasspathConfigurationResolver() { ClassPath classPath = ClassPath.from(Thread.currentThread().getContextClassLoader()); FilteredClasspathResourceResourceProvider componentResourcesProvider = FilteredClasspathResourceResourceProvider.builder() .order(300) .withResourceFilter(new PathFilter("ComponentResources/Configuration")) .withResourceFilter(new NotFilter(new PathFilter("EnvironmentOverrides"))) .withResourceFilter(ExtensionFilter.PROPERTIES_FILTER) .withClassPath(classPath) .build(); FilteredClasspathResourceResourceProvider environmentOverridesResourcesProvider = FilteredClasspathResourceResourceProvider.builder() .order(400) .withResourceFilter( new PathFilter("ComponentResources/Configuration/EnvironmentOverrides/JUNIT")) .withResourceFilter(ExtensionFilter.PROPERTIES_FILTER) .withClassPath(classPath) .build(); FilteredClasspathResourceResourceProvider environmentResourcesProvider = FilteredClasspathResourceResourceProvider.builder() .order(200) .withResourceFilter(new PathFilter("EnvironmentResources/JUNIT")) .withResourceFilter(ExtensionFilter.PROPERTIES_FILTER) .withClassPath(classPath) .build(); FilteredClasspathResourceResourceProvider sharedResourcesProvider = FilteredClasspathResourceResourceProvider.builder() .order(100) .withResourceFilter(new PathFilter("SharedResources")) .withResourceFilter(ExtensionFilter.PROPERTIES_FILTER) .withClassPath(classPath) .build(); FilteredClasspathResourceResourceProvider secureResourcesProvider = FilteredClasspathResourceResourceProvider.builder() .order(500) .secure(true) .withResourceFilter(new PathFilter("SecureResources/JUNIT/Configuration")) .withResourceFilter(ExtensionFilter.PROPERTIES_FILTER) .withClassPath(classPath) .build(); Set<FilteredClasspathResourceResourceProvider> resourceProviders = Sets.newHashSetWithExpectedSize(4); resourceProviders.add(componentResourcesProvider); resourceProviders.add(secureResourcesProvider); resourceProviders.add(sharedResourcesProvider); resourceProviders.add(environmentResourcesProvider); resourceProviders.add(environmentOverridesResourcesProvider); ConfigurationDescriptorResolver<ClasspathResource> combinedConfigurationDescriptorResolver = new ConfigurationDescriptorResolver<ClasspathResource>(); CombinedClasspathConfigurationResolver combinedClasspathConfigurationResolver = new CombinedClasspathConfigurationResolver(combinedConfigurationDescriptorResolver); Set<CombinedClasspathConfiguration> combinedClasspathConfigurations = combinedClasspathConfigurationResolver.resolve(resourceProviders); for (FileBasedConfiguration<ClasspathResource> combinedClasspathConfiguration : combinedClasspathConfigurations) { Logger.getAnonymousLogger().info(combinedClasspathConfiguration.toString()); } }