Search in sources :

Example 1 with AnnotationConfigServletWebServerApplicationContext

use of cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project today-infrastructure by TAKETODAY.

the class ServletComponentScanIntegrationTests method indexedComponentsAreRegistered.

@ParameterizedTest(name = "{0}")
@MethodSource("testConfiguration")
void indexedComponentsAreRegistered(String serverName, Class<?> configuration) throws IOException {
    writeIndex(this.temp);
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    try (URLClassLoader classLoader = new URLClassLoader(new URL[] { this.temp.toURI().toURL() }, getClass().getClassLoader())) {
        this.context.setClassLoader(classLoader);
        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(cn.taketoday.framework.web.context.ServerPortInfoApplicationContextInitializer) AnnotationConfigServletWebServerApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) URLClassLoader(java.net.URLClassLoader) RestTemplate(cn.taketoday.web.client.RestTemplate) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with AnnotationConfigServletWebServerApplicationContext

use of cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project today-framework by TAKETODAY.

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(cn.taketoday.framework.web.context.ServerPortInfoApplicationContextInitializer) AnnotationConfigServletWebServerApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) RestTemplate(cn.taketoday.web.client.RestTemplate) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 3 with AnnotationConfigServletWebServerApplicationContext

use of cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project today-framework by TAKETODAY.

the class ServletComponentScanIntegrationTests method indexedComponentsAreRegistered.

@ParameterizedTest(name = "{0}")
@MethodSource("testConfiguration")
void indexedComponentsAreRegistered(String serverName, Class<?> configuration) throws IOException {
    writeIndex(this.temp);
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    try (URLClassLoader classLoader = new URLClassLoader(new URL[] { this.temp.toURI().toURL() }, getClass().getClassLoader())) {
        this.context.setClassLoader(classLoader);
        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(cn.taketoday.framework.web.context.ServerPortInfoApplicationContextInitializer) AnnotationConfigServletWebServerApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) URLClassLoader(java.net.URLClassLoader) RestTemplate(cn.taketoday.web.client.RestTemplate) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with AnnotationConfigServletWebServerApplicationContext

use of cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project today-framework by TAKETODAY.

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(cn.taketoday.framework.web.context.ServerPortInfoApplicationContextInitializer) MultipartConfigElement(jakarta.servlet.MultipartConfigElement) TestMultipartServlet(cn.taketoday.framework.web.servlet.testcomponents.TestMultipartServlet) AnnotationConfigServletWebServerApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with AnnotationConfigServletWebServerApplicationContext

use of cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebServerApplicationContext in project today-infrastructure by TAKETODAY.

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(cn.taketoday.framework.web.context.ServerPortInfoApplicationContextInitializer) MultipartConfigElement(jakarta.servlet.MultipartConfigElement) TestMultipartServlet(cn.taketoday.framework.web.servlet.testcomponents.TestMultipartServlet) AnnotationConfigServletWebServerApplicationContext(cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ServerPortInfoApplicationContextInitializer (cn.taketoday.framework.web.context.ServerPortInfoApplicationContextInitializer)6 AnnotationConfigServletWebServerApplicationContext (cn.taketoday.framework.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 MethodSource (org.junit.jupiter.params.provider.MethodSource)6 RestTemplate (cn.taketoday.web.client.RestTemplate)4 TestMultipartServlet (cn.taketoday.framework.web.servlet.testcomponents.TestMultipartServlet)2 MultipartConfigElement (jakarta.servlet.MultipartConfigElement)2 URLClassLoader (java.net.URLClassLoader)2