use of cn.taketoday.core.env.PropertySource in project today-framework by TAKETODAY.
the class PropertySourcesPlaceholderConfigurerTests method withNonEnumerablePropertySource.
@Test
public void withNonEnumerablePropertySource() {
StandardBeanFactory bf = new StandardBeanFactory();
bf.registerBeanDefinition("testBean", genericBeanDefinition(TestBean.class).addPropertyValue("name", "${foo}").getBeanDefinition());
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
PropertySource<?> ps = new PropertySource<>("simplePropertySource", new Object()) {
@Override
public Object getProperty(String key) {
return "bar";
}
};
MockEnvironment env = new MockEnvironment();
env.getPropertySources().addFirst(ps);
ppc.setEnvironment(env);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("bar");
}
use of cn.taketoday.core.env.PropertySource in project today-framework by TAKETODAY.
the class ConfigDataEnvironmentTests method processAndApplyMovesDefaultPropertySourceToLast.
@Test
void processAndApplyMovesDefaultPropertySourceToLast(TestInfo info) {
MockPropertySource defaultPropertySource = new MockPropertySource("defaultProperties");
this.environment.getPropertySources().addFirst(defaultPropertySource);
this.environment.setProperty("context.config.location", getConfigLocation(info));
ConfigDataEnvironment configDataEnvironment = new ConfigDataEnvironment(this.bootstrapContext, this.environment, this.resourceLoader, this.additionalProfiles, null);
configDataEnvironment.processAndApply();
List<PropertySource<?>> sources = this.environment.getPropertySources().stream().collect(Collectors.toList());
assertThat(sources.get(sources.size() - 1)).isSameAs(defaultPropertySource);
}
use of cn.taketoday.core.env.PropertySource in project today-framework by TAKETODAY.
the class StandardConfigDataLoader method load.
@Override
public ConfigData load(ConfigDataLoaderContext context, StandardConfigDataResource resource) throws IOException, ConfigDataNotFoundException {
if (resource.isEmptyDirectory()) {
return ConfigData.EMPTY;
}
ConfigDataResourceNotFoundException.throwIfDoesNotExist(resource, resource.getResource());
StandardConfigDataReference reference = resource.getReference();
Resource originTrackedResource = OriginTrackedResource.from(resource.getResource(), Origin.from(reference.getConfigDataLocation()));
String name = String.format("Config resource '%s' via location '%s'", resource, reference.getConfigDataLocation());
List<PropertySource<?>> propertySources = reference.getPropertySourceLoader().load(name, originTrackedResource);
PropertySourceOptions options = (resource.getProfile() != null) ? PROFILE_SPECIFIC : NON_PROFILE_SPECIFIC;
return new ConfigData(propertySources, options);
}
use of cn.taketoday.core.env.PropertySource in project today-infrastructure by TAKETODAY.
the class StandardConfigDataLoader method load.
@Override
public ConfigData load(ConfigDataLoaderContext context, StandardConfigDataResource resource) throws IOException, ConfigDataNotFoundException {
if (resource.isEmptyDirectory()) {
return ConfigData.EMPTY;
}
ConfigDataResourceNotFoundException.throwIfDoesNotExist(resource, resource.getResource());
StandardConfigDataReference reference = resource.getReference();
Resource originTrackedResource = OriginTrackedResource.from(resource.getResource(), Origin.from(reference.getConfigDataLocation()));
String name = String.format("Config resource '%s' via location '%s'", resource, reference.getConfigDataLocation());
List<PropertySource<?>> propertySources = reference.getPropertySourceLoader().load(name, originTrackedResource);
PropertySourceOptions options = (resource.getProfile() != null) ? PROFILE_SPECIFIC : NON_PROFILE_SPECIFIC;
return new ConfigData(propertySources, options);
}
use of cn.taketoday.core.env.PropertySource in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentTests method processAndApplyMovesDefaultPropertySourceToLast.
@Test
void processAndApplyMovesDefaultPropertySourceToLast(TestInfo info) {
MockPropertySource defaultPropertySource = new MockPropertySource("defaultProperties");
this.environment.getPropertySources().addFirst(defaultPropertySource);
this.environment.setProperty("context.config.location", getConfigLocation(info));
ConfigDataEnvironment configDataEnvironment = new ConfigDataEnvironment(this.bootstrapContext, this.environment, this.resourceLoader, this.additionalProfiles, null);
configDataEnvironment.processAndApply();
List<PropertySource<?>> sources = this.environment.getPropertySources().stream().collect(Collectors.toList());
assertThat(sources.get(sources.size() - 1)).isSameAs(defaultPropertySource);
}
Aggregations