use of org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer in project spring-boot by spring-projects.
the class ServletWebServerApplicationContextTests method localPortIsAvailable.
@Test
void localPortIsAvailable() {
addWebServerFactoryBean();
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
ConfigurableEnvironment environment = this.context.getEnvironment();
assertThat(environment.containsProperty("local.server.port")).isTrue();
assertThat(environment.getProperty("local.server.port")).isEqualTo("8080");
}
use of org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer in project spring-boot by spring-projects.
the class ServletComponentScanIntegrationTests method multipartConfigIsHonoured.
@ParameterizedTest(name = "{0}")
@MethodSource("testConfiguration")
void multipartConfigIsHonoured(String serverName, Class<?> configuration) {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.register(configuration);
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
@SuppressWarnings("rawtypes") Map<String, ServletRegistrationBean> beans = this.context.getBeansOfType(ServletRegistrationBean.class);
ServletRegistrationBean<?> servletRegistrationBean = beans.get(TestMultipartServlet.class.getName());
assertThat(servletRegistrationBean).isNotNull();
MultipartConfigElement multipartConfig = servletRegistrationBean.getMultipartConfig();
assertThat(multipartConfig).isNotNull();
assertThat(multipartConfig.getLocation()).isEqualTo("test");
assertThat(multipartConfig.getMaxRequestSize()).isEqualTo(2048);
assertThat(multipartConfig.getMaxFileSize()).isEqualTo(1024);
assertThat(multipartConfig.getFileSizeThreshold()).isEqualTo(512);
}
use of org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer in project spring-boot by spring-projects.
the class ServletComponentScanIntegrationTests method componentsAreRegistered.
@ParameterizedTest(name = "{0}")
@MethodSource("testConfiguration")
void componentsAreRegistered(String serverName, Class<?> configuration) {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.register(configuration);
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
String port = this.context.getEnvironment().getProperty("local.server.port");
String response = new RestTemplate().getForObject("http://localhost:" + port + "/test", String.class);
assertThat(response).isEqualTo("alpha bravo charlie");
}
Aggregations