Search in sources :

Example 76 with AbstractConfiguration

use of org.apache.commons.configuration.AbstractConfiguration in project java-chassis by ServiceComb.

the class TestConfigUtil method testConvertEnvVariable.

@Test
public void testConvertEnvVariable() {
    String someProperty = "cse_service_registry_address";
    AbstractConfiguration config = new DynamicConfiguration();
    config.addProperty(someProperty, "testing");
    AbstractConfiguration result = ConfigUtil.convertEnvVariable(config);
    assertThat(result.getString("cse.service.registry.address"), equalTo("testing"));
    assertThat(result.getString("cse_service_registry_address"), equalTo("testing"));
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) DynamicConfiguration(com.netflix.config.DynamicConfiguration) Test(org.junit.Test)

Example 77 with AbstractConfiguration

use of org.apache.commons.configuration.AbstractConfiguration in project java-chassis by ServiceComb.

the class TestConfigUtil method testAddConfig.

@Test
public void testAddConfig() {
    Map<String, Object> config = new HashMap<>();
    config.put("service_description.name", "service_name_test");
    ConfigUtil.setConfigs(config);
    ConfigUtil.addConfig("service_description.version", "1.0.2");
    ConfigUtil.addConfig("cse.test.enabled", true);
    ConfigUtil.addConfig("cse.test.num", 10);
    AbstractConfiguration configuration = ConfigUtil.createLocalConfig();
    Assert.assertEquals(configuration.getString("service_description.name"), "service_name_test");
    Assert.assertTrue(configuration.getBoolean("cse.test.enabled"));
    Assert.assertEquals(configuration.getInt("cse.test.num"), 10);
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 78 with AbstractConfiguration

use of org.apache.commons.configuration.AbstractConfiguration in project java-chassis by ServiceComb.

the class TestConfigUtil method duplicateServiceCombConfigToCseListValue.

@Test
public void duplicateServiceCombConfigToCseListValue() {
    List<String> list = Arrays.asList("a", "b");
    AbstractConfiguration config = new DynamicConfiguration();
    config.addProperty("cse.list", list);
    Deencapsulation.invoke(ConfigUtil.class, "duplicateCseConfigToServicecomb", config);
    Object result = config.getProperty("servicecomb.list");
    assertThat(result, instanceOf(List.class));
    assertThat(result, equalTo(list));
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) DynamicConfiguration(com.netflix.config.DynamicConfiguration) List(java.util.List) Test(org.junit.Test)

Example 79 with AbstractConfiguration

use of org.apache.commons.configuration.AbstractConfiguration in project zuul by Netflix.

the class ServerTest method beforeTest.

@Before
public void beforeTest() {
    final AbstractConfiguration config = ConfigurationManager.getConfigInstance();
    config.setProperty("zuul.server.netty.socket.force_nio", "true");
    config.setProperty("zuul.server.netty.socket.force_io_uring", "false");
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) Before(org.junit.Before)

Example 80 with AbstractConfiguration

use of org.apache.commons.configuration.AbstractConfiguration in project zuul by Netflix.

the class ZuulFiltersModule method findClassNames.

// Get compiled filter classes to be found on classpath.
@VisibleForTesting
String[] findClassNames(AbstractConfiguration config) {
    // Find individually-specified filter classes.
    String[] filterClassNamesStrArray = config.getStringArray("zuul.filters.classes");
    Stream<String> classNameStream = Arrays.stream(filterClassNamesStrArray).map(String::trim).filter(blank.negate());
    // Find filter classes in specified packages.
    String[] packageNamesStrArray = config.getStringArray("zuul.filters.packages");
    ClassPath cp;
    try {
        cp = ClassPath.from(this.getClass().getClassLoader());
    } catch (IOException e) {
        throw new RuntimeException("Error attempting to read classpath to find filters!", e);
    }
    Stream<String> packageStream = Arrays.stream(packageNamesStrArray).map(String::trim).filter(blank.negate()).flatMap(packageName -> cp.getTopLevelClasses(packageName).stream()).map(ClassPath.ClassInfo::load).filter(ZuulFilter.class::isAssignableFrom).map(Class::getCanonicalName);
    String[] filterClassNames = Stream.concat(classNameStream, packageStream).toArray(String[]::new);
    if (filterClassNames.length != 0) {
        LOG.info("Using filter classnames: ");
        for (String location : filterClassNames) {
            LOG.info("  " + location);
        }
    }
    return filterClassNames;
}
Also used : FilterFactory(com.netflix.zuul.FilterFactory) GuiceFilterFactory(com.netflix.zuul.guice.GuiceFilterFactory) FilenameFilter(java.io.FilenameFilter) Arrays(java.util.Arrays) Logger(org.slf4j.Logger) FilterFileManagerConfig(com.netflix.zuul.FilterFileManager.FilterFileManagerConfig) Predicate(java.util.function.Predicate) FilterUsageNotifier(com.netflix.zuul.FilterUsageNotifier) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) ZuulFilter(com.netflix.zuul.filters.ZuulFilter) Provides(com.google.inject.Provides) BasicFilterUsageNotifier(com.netflix.zuul.BasicFilterUsageNotifier) AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) Stream(java.util.stream.Stream) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ClassPath(com.google.common.reflect.ClassPath) AbstractModule(com.google.inject.AbstractModule) ClassPath(com.google.common.reflect.ClassPath) IOException(java.io.IOException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)80 Test (org.junit.Test)29 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)18 BeforeClass (org.junit.BeforeClass)10 Configuration (org.apache.commons.configuration.Configuration)9 URI (java.net.URI)6 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)6 HttpRequest (com.netflix.client.http.HttpRequest)5 ArrayList (java.util.ArrayList)5 DynamicConfiguration (com.netflix.config.DynamicConfiguration)4 EnvironmentConfiguration (org.apache.commons.configuration.EnvironmentConfiguration)4 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)4 HttpResponse (com.netflix.client.http.HttpResponse)3 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)3 ExpandedConfigurationListenerAdapter (com.netflix.config.ExpandedConfigurationListenerAdapter)3 LinkedHashMap (java.util.LinkedHashMap)3 Properties (java.util.Properties)3 AggregatedConfiguration (com.netflix.config.AggregatedConfiguration)2 ConfigurationManager (com.netflix.config.ConfigurationManager)2 DynamicURLConfiguration (com.netflix.config.DynamicURLConfiguration)2