Search in sources :

Example 1 with DefaultConfigFactory

use of com.ctrip.framework.apollo.spi.DefaultConfigFactory in project apollo by ctripcorp.

the class PureApolloConfigTest method testDefaultConfigWithEnvironmentVariables.

@Test
public void testDefaultConfigWithEnvironmentVariables() throws Exception {
    SystemLambda.withEnvironmentVariable("SPRING_PROFILES_ACTIVE", "test-env").execute(() -> {
        ApolloMockInjectorCustomizer.register(ConfigFactory.class, DefaultConfigFactory::new);
        ConfigFactory configFactory = ApolloInjector.getInstance(ConfigFactory.class);
        Config config = configFactory.create("application");
        Assert.assertEquals("test-env", config.getProperty("SPRING_PROFILES_ACTIVE", null));
    });
}
Also used : DefaultConfigFactory(com.ctrip.framework.apollo.spi.DefaultConfigFactory) Config(com.ctrip.framework.apollo.Config) PureApolloConfigFactory(com.ctrip.framework.apollo.config.data.internals.PureApolloConfigFactory) DefaultConfigFactory(com.ctrip.framework.apollo.spi.DefaultConfigFactory) ConfigFactory(com.ctrip.framework.apollo.spi.ConfigFactory) Test(org.junit.Test)

Example 2 with DefaultConfigFactory

use of com.ctrip.framework.apollo.spi.DefaultConfigFactory in project apollo by ctripcorp.

the class PureApolloConfigTest method testDefaultConfigWithSystemProperties.

@Test
public void testDefaultConfigWithSystemProperties() {
    System.setProperty("spring.profiles.active", "test");
    ApolloMockInjectorCustomizer.register(ConfigFactory.class, DefaultConfigFactory::new);
    ConfigFactory configFactory = ApolloInjector.getInstance(ConfigFactory.class);
    Config config = configFactory.create("application");
    Assert.assertEquals("test", config.getProperty("spring.profiles.active", null));
}
Also used : DefaultConfigFactory(com.ctrip.framework.apollo.spi.DefaultConfigFactory) Config(com.ctrip.framework.apollo.Config) PureApolloConfigFactory(com.ctrip.framework.apollo.config.data.internals.PureApolloConfigFactory) DefaultConfigFactory(com.ctrip.framework.apollo.spi.DefaultConfigFactory) ConfigFactory(com.ctrip.framework.apollo.spi.ConfigFactory) Test(org.junit.Test)

Aggregations

Config (com.ctrip.framework.apollo.Config)2 PureApolloConfigFactory (com.ctrip.framework.apollo.config.data.internals.PureApolloConfigFactory)2 ConfigFactory (com.ctrip.framework.apollo.spi.ConfigFactory)2 DefaultConfigFactory (com.ctrip.framework.apollo.spi.DefaultConfigFactory)2 Test (org.junit.Test)2