@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")); }
@Test public void testServletPathAsPrefix() throws Exception { RelaxedDataBinder binder = new RelaxedDataBinder(this.properties, "server"); binder.bind(new MutablePropertyValues(Collections.singletonMap("server.servletPath", "/foo"))); assertThat(binder.getBindingResult().hasErrors()).isFalse(); assertThat(this.properties.getServletMapping()).isEqualTo("/foo/*"); assertThat(this.properties.getServletPrefix()).isEqualTo("/foo"); }
@Test public void testServerHeader() throws Exception { RelaxedDataBinder binder = new RelaxedDataBinder(this.properties, "server"); binder.bind( new MutablePropertyValues( Collections.singletonMap("server.server-header", "Custom Server"))); assertThat(this.properties.getServerHeader()).isEqualTo("Custom Server"); }
/** * Bind the environment to the {@link SpringApplication}. * * @param environment the environment to bind * @param application the application to bind to */ protected void bindToSpringApplication( ConfigurableEnvironment environment, SpringApplication application) { RelaxedDataBinder binder = new RelaxedDataBinder(application, "spring.main"); binder.setConversionService(this.conversionService); binder.bind(new PropertySourcesPropertyValues(environment.getPropertySources())); }