Search in sources :

Example 16 with MapConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MapConfigurationPropertySource 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 17 with MapConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MapConfigurationPropertySource in project spring-cloud-stream by spring-cloud.

the class BindingServiceTests method createBindingServiceProperties.

private BindingServiceProperties createBindingServiceProperties(HashMap<String, String> properties) {
    BindingServiceProperties bindingServiceProperties = new BindingServiceProperties();
    org.springframework.boot.context.properties.bind.Binder propertiesBinder = new org.springframework.boot.context.properties.bind.Binder(new MapConfigurationPropertySource(properties));
    propertiesBinder.bind("spring.cloud.stream", org.springframework.boot.context.properties.bind.Bindable.ofInstance(bindingServiceProperties));
    return bindingServiceProperties;
}
Also used : ExtendedPropertiesBinder(org.springframework.cloud.stream.binder.ExtendedPropertiesBinder) Binder(org.springframework.cloud.stream.binder.Binder) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource)

Example 18 with MapConfigurationPropertySource

use of org.springframework.boot.context.properties.source.MapConfigurationPropertySource 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 19 with MapConfigurationPropertySource

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

the class ConfigDataActivationContextTests method getCloudPlatformWhenCloudPropertyHasBeenContributedDuringInitialLoadDeducesCloudPlatform.

@Test
void getCloudPlatformWhenCloudPropertyHasBeenContributedDuringInitialLoadDeducesCloudPlatform() {
    Environment environment = createKubernetesEnvironment();
    Binder binder = new Binder(new MapConfigurationPropertySource(Collections.singletonMap("spring.main.cloud-platform", "HEROKU")));
    ConfigDataActivationContext context = new ConfigDataActivationContext(environment, binder);
    assertThat(context.getCloudPlatform()).isEqualTo(CloudPlatform.HEROKU);
}
Also used : Binder(org.springframework.boot.context.properties.bind.Binder) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Environment(org.springframework.core.env.Environment) MockEnvironment(org.springframework.mock.env.MockEnvironment) MapConfigurationPropertySource(org.springframework.boot.context.properties.source.MapConfigurationPropertySource) Test(org.junit.jupiter.api.Test)

Example 20 with MapConfigurationPropertySource

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

the class WebMvcPropertiesTests method bind.

private void bind(Map<String, String> map) {
    ConfigurationPropertySource source = new MapConfigurationPropertySource(map);
    new Binder(source).bind("spring.mvc", Bindable.ofInstance(this.properties));
}
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)

Aggregations

MapConfigurationPropertySource (org.springframework.boot.context.properties.source.MapConfigurationPropertySource)35 Binder (org.springframework.boot.context.properties.bind.Binder)32 Test (org.junit.jupiter.api.Test)21 ConfigurationPropertySource (org.springframework.boot.context.properties.source.ConfigurationPropertySource)11 MockEnvironment (org.springframework.mock.env.MockEnvironment)7 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 LinkedHashMap (java.util.LinkedHashMap)3 Environment (org.springframework.core.env.Environment)3 ArrayList (java.util.ArrayList)2 ApolloClientProperties (com.ctrip.framework.apollo.config.data.extension.properties.ApolloClientProperties)1 DataSourceBeanCreationException (org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.DataSourceBeanCreationException)1 ConfigurationPropertyNameAliases (org.springframework.boot.context.properties.source.ConfigurationPropertyNameAliases)1 Catalog (org.springframework.cloud.servicebroker.model.catalog.Catalog)1 Binder (org.springframework.cloud.stream.binder.Binder)1 ExtendedPropertiesBinder (org.springframework.cloud.stream.binder.ExtendedPropertiesBinder)1 BindingServiceProperties (org.springframework.cloud.stream.config.BindingServiceProperties)1 StandardEnvironment (org.springframework.core.env.StandardEnvironment)1 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)1 BindException (org.springframework.validation.BindException)1