Search in sources :

Example 6 with RelaxedDataBinder

use of org.springframework.boot.bind.RelaxedDataBinder in project spring-boot by spring-projects.

the class ServerPropertiesTests method testAddressBinding.

@Test
public void testAddressBinding() throws Exception {
    RelaxedDataBinder binder = new RelaxedDataBinder(this.properties, "server");
    binder.bind(new MutablePropertyValues(Collections.singletonMap("server.address", "127.0.0.1")));
    assertThat(binder.getBindingResult().hasErrors()).isFalse();
    assertThat(this.properties.getAddress()).isEqualTo(InetAddress.getByName("127.0.0.1"));
}
Also used : RelaxedDataBinder(org.springframework.boot.bind.RelaxedDataBinder) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 7 with RelaxedDataBinder

use of org.springframework.boot.bind.RelaxedDataBinder in project spring-boot by spring-projects.

the class ServerPropertiesTests method testPortBinding.

@Test
public void testPortBinding() throws Exception {
    new RelaxedDataBinder(this.properties, "server").bind(new MutablePropertyValues(Collections.singletonMap("server.port", "9000")));
    assertThat(this.properties.getPort().intValue()).isEqualTo(9000);
}
Also used : RelaxedDataBinder(org.springframework.boot.bind.RelaxedDataBinder) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 8 with RelaxedDataBinder

use of org.springframework.boot.bind.RelaxedDataBinder in project spring-boot by spring-projects.

the class ServerPropertiesTests method testTrailingSlashOfContextPathIsRemoved.

@Test
public void testTrailingSlashOfContextPathIsRemoved() {
    new RelaxedDataBinder(this.properties, "server").bind(new MutablePropertyValues(Collections.singletonMap("server.servlet.contextPath", "/foo/")));
    assertThat(this.properties.getServlet().getContextPath()).isEqualTo("/foo");
}
Also used : RelaxedDataBinder(org.springframework.boot.bind.RelaxedDataBinder) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 9 with RelaxedDataBinder

use of org.springframework.boot.bind.RelaxedDataBinder in project spring-boot by spring-projects.

the class ServerPropertiesTests method testServletPathAsMapping.

@Test
public void testServletPathAsMapping() throws Exception {
    RelaxedDataBinder binder = new RelaxedDataBinder(this.properties, "server");
    binder.bind(new MutablePropertyValues(Collections.singletonMap("server.servlet.path", "/foo/*")));
    assertThat(binder.getBindingResult().hasErrors()).isFalse();
    assertThat(this.properties.getServlet().getServletMapping()).isEqualTo("/foo/*");
    assertThat(this.properties.getServlet().getServletPrefix()).isEqualTo("/foo");
}
Also used : RelaxedDataBinder(org.springframework.boot.bind.RelaxedDataBinder) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) Test(org.junit.Test)

Example 10 with RelaxedDataBinder

use of org.springframework.boot.bind.RelaxedDataBinder in project spring-boot by spring-projects.

the class DataSourceBuilder method bind.

private void bind(DataSource result) {
    MutablePropertyValues properties = new MutablePropertyValues(this.properties);
    new RelaxedDataBinder(result).withAlias("url", "jdbcUrl").withAlias("username", "user").bind(properties);
}
Also used : RelaxedDataBinder(org.springframework.boot.bind.RelaxedDataBinder) MutablePropertyValues(org.springframework.beans.MutablePropertyValues)

Aggregations

RelaxedDataBinder (org.springframework.boot.bind.RelaxedDataBinder)11 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)9 Test (org.junit.Test)7 PropertySourcesPropertyValues (org.springframework.boot.bind.PropertySourcesPropertyValues)2 PropertyValues (org.springframework.beans.PropertyValues)1 RelaxedPropertyResolver (org.springframework.boot.bind.RelaxedPropertyResolver)1 MutablePropertySources (org.springframework.core.env.MutablePropertySources)1 PropertiesPropertySource (org.springframework.core.env.PropertiesPropertySource)1