use of cn.taketoday.context.properties.source.ConfigurationPropertySource in project today-infrastructure by TAKETODAY.
the class InactiveConfigDataAccessExceptionTests method throwIfPropertyFoundWhenPropertyNotFoundDoesNothing.
@Test
void throwIfPropertyFoundWhenPropertyNotFoundDoesNothing() {
ConfigDataEnvironmentContributor contributor = mock(ConfigDataEnvironmentContributor.class);
ConfigurationPropertySource configurationPropertySource = ConfigurationPropertySource.from(this.propertySource);
given(contributor.getConfigurationPropertySource()).willReturn(configurationPropertySource);
InactiveConfigDataAccessException.throwIfPropertyFound(contributor, ConfigurationPropertyName.of("spring"));
}
use of cn.taketoday.context.properties.source.ConfigurationPropertySource in project today-infrastructure by TAKETODAY.
the class ProfilesTests method getDefaultWhenDefaultEnvironmentProfileAndBinderProperty.
@Test
void getDefaultWhenDefaultEnvironmentProfileAndBinderProperty() {
MockEnvironment environment = new MockEnvironment();
environment.setProperty("context.profiles.default", "default");
List<ConfigurationPropertySource> sources = new ArrayList<>();
ConfigurationPropertySources.get(environment).forEach(sources::add);
sources.add(new MapConfigurationPropertySource(Collections.singletonMap("context.profiles.default", "a,b,c")));
Binder binder = new Binder(sources);
Profiles profiles = new Profiles(environment, binder, null);
assertThat(profiles.getDefault()).containsExactly("default");
}
use of cn.taketoday.context.properties.source.ConfigurationPropertySource in project today-infrastructure by TAKETODAY.
the class MapBinder method bindAggregate.
@Override
protected Object bindAggregate(ConfigurationPropertyName name, Bindable<?> target, AggregateElementBinder elementBinder) {
Map<Object, Object> map = CollectionUtils.createMap((target.getValue() != null) ? Map.class : target.getType().resolve(Object.class), 0);
Bindable<?> resolvedTarget = resolveTarget(target);
boolean hasDescendants = hasDescendants(name);
for (ConfigurationPropertySource source : getContext().getSources()) {
if (!ConfigurationPropertyName.EMPTY.equals(name)) {
ConfigurationProperty property = source.getConfigurationProperty(name);
if (property != null && !hasDescendants) {
return getContext().getConverter().convert(property.getValue(), target);
}
source = source.filter(name::isAncestorOf);
}
new EntryBinder(name, resolvedTarget, elementBinder).bindEntries(source, map);
}
return map.isEmpty() ? null : map;
}
use of cn.taketoday.context.properties.source.ConfigurationPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentContributor method ofUnboundImport.
/**
* Factory method to create an {@link Kind#UNBOUND_IMPORT unbound import} contributor.
* This contributor has been actively imported from another contributor and may itself
* import further contributors later.
*
* @param location the location of this contributor
* @param resource the config data resource
* @param profileSpecific if the contributor is from a profile specific import
* @param configData the config data
* @param propertySourceIndex the index of the property source that should be used
* @return a new {@link ConfigDataEnvironmentContributor} instance
*/
static ConfigDataEnvironmentContributor ofUnboundImport(@Nullable ConfigDataLocation location, @Nullable ConfigDataResource resource, boolean profileSpecific, ConfigData configData, int propertySourceIndex) {
PropertySource<?> propertySource = configData.getPropertySources().get(propertySourceIndex);
Options options = configData.getOptions(propertySource);
ConfigurationPropertySource configurationPropertySource = ConfigurationPropertySource.from(propertySource);
return new ConfigDataEnvironmentContributor(Kind.UNBOUND_IMPORT, location, resource, profileSpecific, propertySource, configurationPropertySource, null, options, null);
}
use of cn.taketoday.context.properties.source.ConfigurationPropertySource in project today-infrastructure by TAKETODAY.
the class ConfigDataEnvironmentContributors method getBinder.
private Binder getBinder(@Nullable ConfigDataActivationContext activationContext, Predicate<ConfigDataEnvironmentContributor> filter, Set<BinderOption> options) {
boolean failOnInactiveSource = options.contains(BinderOption.FAIL_ON_BIND_TO_INACTIVE_SOURCE);
Iterable<ConfigurationPropertySource> sources = () -> getBinderSources(filter.and((contributor) -> failOnInactiveSource || contributor.isActive(activationContext)));
var placeholdersResolver = new ConfigDataEnvironmentContributorPlaceholdersResolver(this.root, activationContext, null, failOnInactiveSource);
BindHandler bindHandler = !failOnInactiveSource ? null : new InactiveSourceChecker(activationContext);
return new Binder(sources, placeholdersResolver, null, null, bindHandler);
}
Aggregations