Search in sources :

Example 11 with ConfigurationPropertySource

use of org.springframework.boot.context.properties.source.ConfigurationPropertySource in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceBrokerPropertiesTest method bindProperties.

private ServiceBrokerProperties bindProperties() {
    ConfigurationPropertySource source = new MapConfigurationPropertySource(this.map);
    Binder binder = new Binder(source);
    ServiceBrokerProperties serviceBrokerProperties = new ServiceBrokerProperties();
    binder.bind(PREFIX, Bindable.ofInstance(serviceBrokerProperties));
    return serviceBrokerProperties;
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource)

Example 12 with ConfigurationPropertySource

use of org.springframework.boot.context.properties.source.ConfigurationPropertySource in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceBrokerPropertiesTest method fullCatalog.

@Test
public void fullCatalog() {
    Map<String, String> map = new HashMap<>();
    map.put("spring.cloud.openservicebroker.catalog.services[0].id", "service-one-id");
    map.put("spring.cloud.openservicebroker.catalog.services[0].name", "Service One");
    map.put("spring.cloud.openservicebroker.catalog.services[0].description", "Description for Service One");
    map.put("spring.cloud.openservicebroker.catalog.services[0].bindable", "true");
    map.put("spring.cloud.openservicebroker.catalog.services[0].bindings-retrievable", "true");
    map.put("spring.cloud.openservicebroker.catalog.services[0].instances-retrievable", "true");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plan-updateable", "true");
    map.put("spring.cloud.openservicebroker.catalog.services[0].metadata[key1]", "value1");
    map.put("spring.cloud.openservicebroker.catalog.services[0].metadata[key2]", "value2");
    map.put("spring.cloud.openservicebroker.catalog.services[0].requires[0]", "syslog_drain");
    map.put("spring.cloud.openservicebroker.catalog.services[0].requires[1]", "route_forwarding");
    map.put("spring.cloud.openservicebroker.catalog.services[0].tags[0]", "tag1");
    map.put("spring.cloud.openservicebroker.catalog.services[0].tags[1]", "tag2");
    map.put("spring.cloud.openservicebroker.catalog.services[0].dashboard-client.id", "dashboard-id");
    map.put("spring.cloud.openservicebroker.catalog.services[0].dashboard-client.secret", "dashboard-secret");
    map.put("spring.cloud.openservicebroker.catalog.services[0].dashboard-client.redirect-uri", "dashboard-redirect-uri");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[0].id", "plan-one-id");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[0].name", "Plan One");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[0].description", "Description for Plan One");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[1].id", "plan-two-id");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[1].name", "Plan Two");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[1].description", "Description for Plan Two");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[1].metadata[key1]", "value1");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[1].metadata[key2]", "value2");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[1].bindable", "true");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[1].free", "true");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[1].schemas.serviceinstance.create.parameters[$schema]", "http://example.com/service/create/schema");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[1].schemas.serviceinstance.create.parameters[type]", "object");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[1].schemas.serviceinstance.update.parameters[$schema]", "http://example.com/service/update/schema");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[1].schemas.serviceinstance.update.parameters[type]", "object");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[1].schemas.servicebinding.create.parameters[$schema]", "http://example.com/service/create/schema");
    map.put("spring.cloud.openservicebroker.catalog.services[0].plans[1].schemas.servicebinding.create.parameters[type]", "object");
    map.put("spring.cloud.openservicebroker.catalog.services[1].id", "service-two-id");
    map.put("spring.cloud.openservicebroker.catalog.services[1].name", "Service Two");
    map.put("spring.cloud.openservicebroker.catalog.services[1].description", "Description for Service Two");
    map.put("spring.cloud.openservicebroker.catalog.services[1].plans[0].id", "plan-one-id");
    map.put("spring.cloud.openservicebroker.catalog.services[1].plans[0].name", "Plan One");
    map.put("spring.cloud.openservicebroker.catalog.services[1].plans[0].description", "Description for Plan One");
    ConfigurationPropertySource source = new MapConfigurationPropertySource(map);
    Binder binder = new Binder(source);
    ServiceBrokerProperties properties = new ServiceBrokerProperties();
    binder.bind("spring.cloud.openservicebroker", Bindable.ofInstance(properties));
    assertThat(properties.getCatalog()).isNotNull();
    assertThat(properties.getCatalog().getServices()).hasSize(2);
    assertThat(properties.getCatalog().getServices().get(0).getId()).isEqualTo("service-one-id");
    assertThat(properties.getCatalog().getServices().get(0).getName()).isEqualTo("Service One");
    assertThat(properties.getCatalog().getServices().get(0).getDescription()).isEqualTo("Description for Service One");
    assertThat(properties.getCatalog().getServices().get(0).isBindable()).isTrue();
    assertThat(properties.getCatalog().getServices().get(0).isBindingsRetrievable()).isTrue();
    assertThat(properties.getCatalog().getServices().get(0).isInstancesRetrievable()).isTrue();
    assertThat(properties.getCatalog().getServices().get(0).isPlanUpdateable()).isTrue();
    assertThat(properties.getCatalog().getServices().get(0).getMetadata()).containsOnly(entry("key1", "value1"), entry("key2", "value2"));
    assertThat(properties.getCatalog().getServices().get(0).getRequires()).containsOnly("syslog_drain", "route_forwarding");
    assertThat(properties.getCatalog().getServices().get(0).getTags()).containsOnly("tag1", "tag2");
    assertThat(properties.getCatalog().getServices().get(0).getDashboardClient().getId()).isEqualTo("dashboard-id");
    assertThat(properties.getCatalog().getServices().get(0).getDashboardClient().getSecret()).isEqualTo("dashboard-secret");
    assertThat(properties.getCatalog().getServices().get(0).getDashboardClient().getRedirectUri()).isEqualTo("dashboard-redirect-uri");
    assertThat(properties.getCatalog().getServices().get(0).getPlans()).hasSize(2);
    assertThat(properties.getCatalog().getServices().get(0).getPlans().get(0).getId()).isEqualTo("plan-one-id");
    assertThat(properties.getCatalog().getServices().get(0).getPlans().get(0).getName()).isEqualTo("Plan One");
    assertThat(properties.getCatalog().getServices().get(0).getPlans().get(0).getDescription()).isEqualTo("Description for Plan One");
    assertThat(properties.getCatalog().getServices().get(0).getPlans().get(1).getId()).isEqualTo("plan-two-id");
    assertThat(properties.getCatalog().getServices().get(0).getPlans().get(1).getName()).isEqualTo("Plan Two");
    assertThat(properties.getCatalog().getServices().get(0).getPlans().get(1).getDescription()).isEqualTo("Description for Plan Two");
    assertThat(properties.getCatalog().getServices().get(0).getPlans().get(1).getMetadata()).containsOnly(entry("key1", "value1"), entry("key2", "value2"));
    assertThat(properties.getCatalog().getServices().get(0).getPlans().get(1).isBindable()).isTrue();
    assertThat(properties.getCatalog().getServices().get(0).getPlans().get(1).isFree()).isTrue();
    assertThat(properties.getCatalog().getServices().get(0).getPlans().get(1).getSchemas().getServiceInstance().getCreate().getParameters()).containsOnly(entry("$schema", "http://example.com/service/create/schema"), entry("type", "object"));
    assertThat(properties.getCatalog().getServices().get(0).getPlans().get(1).getSchemas().getServiceInstance().getUpdate().getParameters()).containsOnly(entry("$schema", "http://example.com/service/update/schema"), entry("type", "object"));
    assertThat(properties.getCatalog().getServices().get(0).getPlans().get(1).getSchemas().getServiceBinding().getCreate().getParameters()).containsOnly(entry("$schema", "http://example.com/service/create/schema"), entry("type", "object"));
    assertThat(properties.getCatalog().getServices().get(1).getId()).isEqualTo("service-two-id");
    assertThat(properties.getCatalog().getServices().get(1).getName()).isEqualTo("Service Two");
    assertThat(properties.getCatalog().getServices().get(1).getDescription()).isEqualTo("Description for Service Two");
    assertThat(properties.getCatalog().getServices().get(1).getPlans()).hasSize(1);
    assertThat(properties.getCatalog().getServices().get(1).getPlans().get(0).getId()).isEqualTo("plan-one-id");
    assertThat(properties.getCatalog().getServices().get(1).getPlans().get(0).getName()).isEqualTo("Plan One");
    assertThat(properties.getCatalog().getServices().get(1).getPlans().get(0).getDescription()).isEqualTo("Description for Plan One");
    Catalog catalog = properties.getCatalog().toModel();
    assertThat(catalog.getServiceDefinitions().get(0).getId()).isEqualTo("service-one-id");
    assertThat(catalog.getServiceDefinitions().get(0).getName()).isEqualTo("Service One");
    assertThat(catalog.getServiceDefinitions().get(0).getDescription()).isEqualTo("Description for Service One");
    assertThat(catalog.getServiceDefinitions().get(0).isBindable()).isTrue();
    assertThat(catalog.getServiceDefinitions().get(0).isBindingsRetrievable()).isTrue();
    assertThat(catalog.getServiceDefinitions().get(0).isInstancesRetrievable()).isTrue();
    assertThat(catalog.getServiceDefinitions().get(0).isPlanUpdateable()).isTrue();
    assertThat(catalog.getServiceDefinitions().get(0).getMetadata()).containsOnly(entry("key1", "value1"), entry("key2", "value2"));
    assertThat(catalog.getServiceDefinitions().get(0).getRequires()).containsOnly("syslog_drain", "route_forwarding");
    assertThat(catalog.getServiceDefinitions().get(0).getTags()).containsOnly("tag1", "tag2");
    assertThat(catalog.getServiceDefinitions().get(0).getDashboardClient().getId()).isEqualTo("dashboard-id");
    assertThat(catalog.getServiceDefinitions().get(0).getDashboardClient().getSecret()).isEqualTo("dashboard-secret");
    assertThat(catalog.getServiceDefinitions().get(0).getDashboardClient().getRedirectUri()).isEqualTo("dashboard-redirect-uri");
    assertThat(catalog.getServiceDefinitions().get(0).getPlans().get(0).getId()).isEqualTo("plan-one-id");
    assertThat(catalog.getServiceDefinitions().get(0).getPlans().get(0).getName()).isEqualTo("Plan One");
    assertThat(catalog.getServiceDefinitions().get(0).getPlans().get(0).getDescription()).isEqualTo("Description for Plan One");
    assertThat(catalog.getServiceDefinitions().get(0).getPlans().get(1).getId()).isEqualTo("plan-two-id");
    assertThat(catalog.getServiceDefinitions().get(0).getPlans().get(1).getName()).isEqualTo("Plan Two");
    assertThat(catalog.getServiceDefinitions().get(0).getPlans().get(1).getDescription()).isEqualTo("Description for Plan Two");
    assertThat(catalog.getServiceDefinitions().get(0).getPlans().get(1).getMetadata()).containsOnly(entry("key1", "value1"), entry("key2", "value2"));
    assertThat(catalog.getServiceDefinitions().get(0).getPlans().get(1).isBindable()).isTrue();
    assertThat(catalog.getServiceDefinitions().get(0).getPlans().get(1).isFree()).isTrue();
    assertThat(catalog.getServiceDefinitions().get(0).getPlans().get(1).getSchemas().getServiceInstanceSchema().getCreateMethodSchema().getParameters()).containsOnly(entry("$schema", "http://example.com/service/create/schema"), entry("type", "object"));
    assertThat(catalog.getServiceDefinitions().get(0).getPlans().get(1).getSchemas().getServiceInstanceSchema().getUpdateMethodSchema().getParameters()).containsOnly(entry("$schema", "http://example.com/service/update/schema"), entry("type", "object"));
    assertThat(catalog.getServiceDefinitions().get(0).getPlans().get(1).getSchemas().getServiceBindingSchema().getCreateMethodSchema().getParameters()).containsOnly(entry("$schema", "http://example.com/service/create/schema"), entry("type", "object"));
    assertThat(catalog.getServiceDefinitions().get(1).getId()).isEqualTo("service-two-id");
    assertThat(catalog.getServiceDefinitions().get(1).getName()).isEqualTo("Service Two");
    assertThat(catalog.getServiceDefinitions().get(1).getDescription()).isEqualTo("Description for Service Two");
    assertThat(catalog.getServiceDefinitions().get(1).getPlans().get(0).getId()).isEqualTo("plan-one-id");
    assertThat(catalog.getServiceDefinitions().get(1).getPlans().get(0).getName()).isEqualTo("Plan One");
    assertThat(catalog.getServiceDefinitions().get(1).getPlans().get(0).getDescription()).isEqualTo("Description for Plan One");
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) HashMap(java.util.HashMap) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) Catalog(org.springframework.cloud.servicebroker.model.catalog.Catalog) Test(org.junit.Test)

Example 13 with ConfigurationPropertySource

use of org.springframework.boot.context.properties.source.ConfigurationPropertySource in project dubbo by alibaba.

the class BinderDubboConfigBinder method bind.

@Override
public void bind(Map<String, Object> configurationProperties, boolean ignoreUnknownFields, boolean ignoreInvalidFields, Object configurationBean) {
    Iterable<PropertySource<?>> propertySources = asList(new MapPropertySource("internal", configurationProperties));
    // Converts ConfigurationPropertySources
    Iterable<ConfigurationPropertySource> configurationPropertySources = from(propertySources);
    // Wrap Bindable from DubboConfig instance
    Bindable bindable = Bindable.ofInstance(configurationBean);
    Binder binder = new Binder(configurationPropertySources, new PropertySourcesPlaceholdersResolver(propertySources));
    // Get BindHandler
    BindHandler bindHandler = getBindHandler(ignoreUnknownFields, ignoreInvalidFields);
    // Bind
    binder.bind("", bindable, bindHandler);
}
Also used : DubboConfigBinder(org.apache.dubbo.config.spring.context.properties.DubboConfigBinder) ConfigurationBeanBinder(com.alibaba.spring.context.config.ConfigurationBeanBinder) Binder(org.springframework.boot.context.properties.bind.Binder) MapPropertySource(org.springframework.core.env.MapPropertySource) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) Bindable(org.springframework.boot.context.properties.bind.Bindable) PropertySourcesPlaceholdersResolver(org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver) NoUnboundElementsBindHandler(org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler) IgnoreErrorsBindHandler(org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler) BindHandler(org.springframework.boot.context.properties.bind.BindHandler) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource) PropertySource(org.springframework.core.env.PropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource)

Example 14 with ConfigurationPropertySource

use of org.springframework.boot.context.properties.source.ConfigurationPropertySource in project spring-boot by spring-projects.

the class ConfigDataEnvironmentContributor method withBoundProperties.

/**
 * Create a new {@link ConfigDataEnvironmentContributor} with bound
 * {@link ConfigDataProperties}.
 * @param contributors the contributors used for binding
 * @param activationContext the activation context
 * @return a new contributor instance
 */
ConfigDataEnvironmentContributor withBoundProperties(Iterable<ConfigDataEnvironmentContributor> contributors, ConfigDataActivationContext activationContext) {
    Iterable<ConfigurationPropertySource> sources = Collections.singleton(getConfigurationPropertySource());
    PlaceholdersResolver placeholdersResolver = new ConfigDataEnvironmentContributorPlaceholdersResolver(contributors, activationContext, this, true);
    Binder binder = new Binder(sources, placeholdersResolver, null, null, null);
    ConfigDataProperties properties = ConfigDataProperties.get(binder);
    if (properties != null && this.configDataOptions.contains(ConfigData.Option.IGNORE_IMPORTS)) {
        properties = properties.withoutImports();
    }
    return new ConfigDataEnvironmentContributor(Kind.BOUND_IMPORT, this.location, this.resource, this.fromProfileSpecificImport, this.propertySource, this.configurationPropertySource, properties, this.configDataOptions, null);
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) PlaceholdersResolver(org.springframework.boot.context.properties.bind.PlaceholdersResolver) ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource)

Example 15 with ConfigurationPropertySource

use of org.springframework.boot.context.properties.source.ConfigurationPropertySource in project spring-boot by spring-projects.

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(ConfigDataLocation location, ConfigDataResource resource, boolean profileSpecific, ConfigData configData, int propertySourceIndex) {
    PropertySource<?> propertySource = configData.getPropertySources().get(propertySourceIndex);
    ConfigData.Options options = configData.getOptions(propertySource);
    ConfigurationPropertySource configurationPropertySource = ConfigurationPropertySource.from(propertySource);
    return new ConfigDataEnvironmentContributor(Kind.UNBOUND_IMPORT, location, resource, profileSpecific, propertySource, configurationPropertySource, null, options, null);
}
Also used : ConfigurationPropertySource(org.springframework.boot.context.properties.source.ConfigurationPropertySource)

Aggregations

ConfigurationPropertySource (org.springframework.boot.context.properties.source.ConfigurationPropertySource)24 Binder (org.springframework.boot.context.properties.bind.Binder)17 MapConfigurationPropertySource (org.springframework.boot.context.properties.source.MapConfigurationPropertySource)11 Test (org.junit.jupiter.api.Test)6 ArrayList (java.util.ArrayList)4 BindHandler (org.springframework.boot.context.properties.bind.BindHandler)4 Bindable (org.springframework.boot.context.properties.bind.Bindable)4 HashMap (java.util.HashMap)3 PlaceholdersResolver (org.springframework.boot.context.properties.bind.PlaceholdersResolver)3 MapPropertySource (org.springframework.core.env.MapPropertySource)3 PropertySource (org.springframework.core.env.PropertySource)3 ConfigurationBeanBinder (com.alibaba.spring.context.config.ConfigurationBeanBinder)2 List (java.util.List)2 Map (java.util.Map)2 DubboConfigBinder (org.apache.dubbo.config.spring.context.properties.DubboConfigBinder)2 Test (org.junit.Test)2 PropertySourcesPlaceholdersResolver (org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver)2 IgnoreErrorsBindHandler (org.springframework.boot.context.properties.bind.handler.IgnoreErrorsBindHandler)2 NoUnboundElementsBindHandler (org.springframework.boot.context.properties.bind.handler.NoUnboundElementsBindHandler)2 ConfigurationProperty (org.springframework.boot.context.properties.source.ConfigurationProperty)2