Search in sources :

Example 11 with ServerPortInfoApplicationContextInitializer

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");
}
Also used : ServerPortInfoApplicationContextInitializer(org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) Test(org.junit.jupiter.api.Test)

Example 12 with ServerPortInfoApplicationContextInitializer

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);
}
Also used : ServerPortInfoApplicationContextInitializer(org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer) MultipartConfigElement(jakarta.servlet.MultipartConfigElement) TestMultipartServlet(org.springframework.boot.web.servlet.testcomponents.TestMultipartServlet) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 13 with ServerPortInfoApplicationContextInitializer

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");
}
Also used : ServerPortInfoApplicationContextInitializer(org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) RestTemplate(org.springframework.web.client.RestTemplate) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ServerPortInfoApplicationContextInitializer (org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer)13 AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)6 Test (org.junit.Test)5 RestTemplate (org.springframework.web.client.RestTemplate)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 Type (java.lang.reflect.Type)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Test (org.junit.jupiter.api.Test)2 TestMultipartServlet (org.springframework.boot.web.servlet.testcomponents.TestMultipartServlet)2 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)2 SimpleMessageConverter (org.springframework.messaging.converter.SimpleMessageConverter)2 StompCommand (org.springframework.messaging.simp.stomp.StompCommand)2 StompFrameHandler (org.springframework.messaging.simp.stomp.StompFrameHandler)2 StompHeaders (org.springframework.messaging.simp.stomp.StompHeaders)2 StompSession (org.springframework.messaging.simp.stomp.StompSession)2 StompSessionHandler (org.springframework.messaging.simp.stomp.StompSessionHandler)2 StompSessionHandlerAdapter (org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter)2 WebSocketStompClient (org.springframework.web.socket.messaging.WebSocketStompClient)2