Search in sources :

Example 6 with AnnotationConfigServletWebApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext in project spring-boot by spring-projects.

the class MappingsEndpointTests method prepareContextSupplier.

@SuppressWarnings("unchecked")
private Supplier<ConfigurableWebApplicationContext> prepareContextSupplier() {
    ServletContext servletContext = mock(ServletContext.class);
    given(servletContext.getInitParameterNames()).willReturn(Collections.emptyEnumeration());
    given(servletContext.getAttributeNames()).willReturn(Collections.emptyEnumeration());
    FilterRegistration filterRegistration = mock(FilterRegistration.class);
    given((Map<String, FilterRegistration>) servletContext.getFilterRegistrations()).willReturn(Collections.singletonMap("testFilter", filterRegistration));
    ServletRegistration servletRegistration = mock(ServletRegistration.class);
    given((Map<String, ServletRegistration>) servletContext.getServletRegistrations()).willReturn(Collections.singletonMap("testServlet", servletRegistration));
    return () -> {
        AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext();
        context.setServletContext(servletContext);
        return context;
    };
}
Also used : ServletRegistration(jakarta.servlet.ServletRegistration) AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext) ServletContext(jakarta.servlet.ServletContext) Map(java.util.Map) FilterRegistration(jakarta.servlet.FilterRegistration)

Example 7 with AnnotationConfigServletWebApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext in project spring-boot by spring-projects.

the class FreeMarkerAutoConfigurationServletIntegrationTests method load.

private void load(Class<?> config, String... env) {
    this.context = new AnnotationConfigServletWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    TestPropertyValues.of(env).applyTo(this.context);
    this.context.register(config);
    this.context.refresh();
}
Also used : AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext)

Example 8 with AnnotationConfigServletWebApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext in project spring-boot by spring-projects.

the class HypermediaAutoConfigurationWithoutJacksonTests method jacksonRelatedConfigurationBacksOff.

@Test
void jacksonRelatedConfigurationBacksOff() {
    this.context = new AnnotationConfigServletWebApplicationContext();
    this.context.register(BaseConfig.class);
    this.context.setServletContext(new MockServletContext());
    this.context.refresh();
}
Also used : AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 9 with AnnotationConfigServletWebApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext in project spring-boot by spring-projects.

the class RepositoryRestMvcAutoConfigurationTests method load.

private void load(Class<?> config, String... environment) {
    AnnotationConfigServletWebApplicationContext applicationContext = new AnnotationConfigServletWebApplicationContext();
    applicationContext.setServletContext(new MockServletContext());
    applicationContext.register(config, BaseConfiguration.class);
    TestPropertyValues.of(environment).applyTo(applicationContext);
    applicationContext.refresh();
    this.context = applicationContext;
}
Also used : AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext)

Example 10 with AnnotationConfigServletWebApplicationContext

use of org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext in project spring-boot by spring-projects.

the class HttpEncodingAutoConfigurationTests method doLoad.

private AnnotationConfigServletWebApplicationContext doLoad(Class<?>[] configs, String... environment) {
    AnnotationConfigServletWebApplicationContext applicationContext = new AnnotationConfigServletWebApplicationContext();
    TestPropertyValues.of(environment).applyTo(applicationContext);
    applicationContext.register(configs);
    applicationContext.register(MinimalWebAutoConfiguration.class, HttpEncodingAutoConfiguration.class);
    applicationContext.setServletContext(new MockServletContext());
    applicationContext.refresh();
    return applicationContext;
}
Also used : AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext) MockServletContext(org.springframework.mock.web.MockServletContext)

Aggregations

AnnotationConfigServletWebApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext)23 Test (org.junit.jupiter.api.Test)16 MockServletContext (org.springframework.mock.web.MockServletContext)12 MockMvc (org.springframework.test.web.servlet.MockMvc)8 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)2 Filter (jakarta.servlet.Filter)1 FilterRegistration (jakarta.servlet.FilterRegistration)1 ServletContext (jakarta.servlet.ServletContext)1 ServletRegistration (jakarta.servlet.ServletRegistration)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 WebMvcEndpointHandlerMapping (org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping)1 PropertyPlaceholderAutoConfiguration (org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration)1 DispatcherFilter (org.springframework.boot.devtools.remote.server.DispatcherFilter)1 DeferredLinesWriter (org.springframework.boot.test.autoconfigure.web.servlet.SpringBootMockMvcBuilderCustomizer.DeferredLinesWriter)1 ReactiveWebApplicationContextRunner (org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner)1 WebApplicationContextRunner (org.springframework.boot.test.context.runner.WebApplicationContextRunner)1