Search in sources :

Example 21 with AnnotationConfigServletWebApplicationContext

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

the class WebMvcEndpointIntegrationTests method linksAreProvidedToAllEndpointTypes.

@Test
void linksAreProvidedToAllEndpointTypes() throws Exception {
    this.context = new AnnotationConfigServletWebApplicationContext();
    this.context.register(DefaultConfiguration.class, EndpointsConfiguration.class);
    TestPropertyValues.of("management.endpoints.web.exposure.include=*").applyTo(this.context);
    MockMvc mockMvc = doCreateMockMvc();
    mockMvc.perform(get("/actuator").accept("*/*")).andExpect(status().isOk()).andExpect(jsonPath("_links", both(hasKey("beans")).and(hasKey("servlet")).and(hasKey("restcontroller")).and(hasKey("controller"))));
}
Also used : AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.jupiter.api.Test)

Example 22 with AnnotationConfigServletWebApplicationContext

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

the class WebMvcEndpointIntegrationTests method linksPageIsNotAvailableWhenDisabled.

@Test
void linksPageIsNotAvailableWhenDisabled() throws Exception {
    this.context = new AnnotationConfigServletWebApplicationContext();
    this.context.register(DefaultConfiguration.class, EndpointsConfiguration.class);
    TestPropertyValues.of("management.endpoints.web.discovery.enabled=false").applyTo(this.context);
    MockMvc mockMvc = doCreateMockMvc();
    mockMvc.perform(get("/actuator").accept("*/*")).andExpect(status().isNotFound());
}
Also used : AnnotationConfigServletWebApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext) MockMvc(org.springframework.test.web.servlet.MockMvc) Test(org.junit.jupiter.api.Test)

Example 23 with AnnotationConfigServletWebApplicationContext

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

the class WebMvcEndpointIntegrationTests method endpointsAreSecureByDefaultWithCustomBasePath.

@Test
void endpointsAreSecureByDefaultWithCustomBasePath() throws Exception {
    this.context = new AnnotationConfigServletWebApplicationContext();
    this.context.register(SecureConfiguration.class);
    TestPropertyValues.of("management.endpoints.web.base-path:/management").applyTo(this.context);
    MockMvc mockMvc = createSecureMockMvc();
    mockMvc.perform(get("/management/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)

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