Search in sources :

Example 1 with AnnotationConfigServletWebApplicationContext

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

the class WebMvcEndpointIntegrationTests method endpointsAreSecureByDefault.

@Test
void endpointsAreSecureByDefault() throws Exception {
    this.context = new AnnotationConfigServletWebApplicationContext();
    this.context.register(SecureConfiguration.class);
    MockMvc mockMvc = createSecureMockMvc();
    mockMvc.perform(get("/actuator/beans").accept(MediaType.APPLICATION_JSON)).andExpect(status().isUnauthorized());
}
Also used : AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.jupiter.api.Test)

Example 2 with AnnotationConfigServletWebApplicationContext

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

the class WebMvcEndpointIntegrationTests method endpointsAreSecureWithActuatorRoleWithCustomBasePath.

@Test
void endpointsAreSecureWithActuatorRoleWithCustomBasePath() throws Exception {
    TestSecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
    this.context = new AnnotationConfigServletWebApplicationContext();
    this.context.register(SecureConfiguration.class);
    TestPropertyValues.of("management.endpoints.web.base-path:/management", "management.endpoints.web.exposure.include=*").applyTo(this.context);
    MockMvc mockMvc = createSecureMockMvc();
    mockMvc.perform(get("/management/beans")).andExpect(status().isOk());
}
Also used : AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext) TestingAuthenticationToken(org.springframework.security.authentication.TestingAuthenticationToken) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.jupiter.api.Test)

Example 3 with AnnotationConfigServletWebApplicationContext

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

the class WebMvcEndpointIntegrationTests method webMvcEndpointHandlerMappingIsConfiguredWithPathPatternParser.

@Test
void webMvcEndpointHandlerMappingIsConfiguredWithPathPatternParser() {
    this.context = new AnnotationConfigServletWebApplicationContext();
    this.context.register(DefaultConfiguration.class);
    this.context.setServletContext(new MockServletContext());
    this.context.refresh();
    WebMvcEndpointHandlerMapping handlerMapping = this.context.getBean(WebMvcEndpointHandlerMapping.class);
    assertThat(handlerMapping.getPatternParser()).isEqualTo(WebMvcAutoConfiguration.pathPatternParser);
}
Also used : AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext) WebMvcEndpointHandlerMapping(org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.jupiter.api.Test)

Example 4 with AnnotationConfigServletWebApplicationContext

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

the class ConditionalOnWarDeploymentTests method embeddedServletWebApplicationShouldNotMatch.

@Test
void embeddedServletWebApplicationShouldNotMatch() {
    WebApplicationContextRunner contextRunner = new WebApplicationContextRunner(AnnotationConfigServletWebApplicationContext::new);
    contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> assertThat(context).doesNotHaveBean("forWar"));
}
Also used : ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext) Test(org.junit.jupiter.api.Test)

Example 5 with AnnotationConfigServletWebApplicationContext

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

the class MustacheAutoConfigurationTests method loadWithServlet.

private void loadWithServlet(Class<?> config) {
    this.webContext = new AnnotationConfigServletWebApplicationContext();
    TestPropertyValues.of("spring.mustache.prefix=classpath:/mustache-templates/").applyTo(this.webContext);
    if (config != null) {
        this.webContext.register(config);
    }
    this.webContext.register(BaseConfiguration.class);
    this.webContext.refresh();
}
Also used : AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext)

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