Search in sources :

Example 41 with AnnotationConfigServletWebServerApplicationContext

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

the class ServletWebServerFactoryAutoConfigurationTests method webServerHasNoServletContext.

@Test
public void webServerHasNoServletContext() throws Exception {
    this.context = new AnnotationConfigServletWebServerApplicationContext(EnsureWebServerHasNoServletContext.class, BaseConfiguration.class);
    verifyContext();
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) Test(org.junit.Test)

Example 42 with AnnotationConfigServletWebServerApplicationContext

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

the class ServletWebServerFactoryAutoConfigurationTests method contextAlreadyHasDispatcherServlet.

@Test
public void contextAlreadyHasDispatcherServlet() throws Exception {
    this.context = new AnnotationConfigServletWebServerApplicationContext(SpringServletConfiguration.class, BaseConfiguration.class);
    verifyContext();
    assertThat(this.context.getBeanNamesForType(DispatcherServlet.class).length).isEqualTo(2);
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) Test(org.junit.Test)

Example 43 with AnnotationConfigServletWebServerApplicationContext

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

the class ServletWebServerServletContextListenerTests method servletContextListenerBeanIsCalled.

private void servletContextListenerBeanIsCalled(Class<?> configuration) {
    AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext(ServletContextListenerBeanConfiguration.class, configuration);
    ServletContextListener servletContextListener = context.getBean("servletContextListener", ServletContextListener.class);
    verify(servletContextListener).contextInitialized(any(ServletContextEvent.class));
    context.close();
}
Also used : ServletContextListener(javax.servlet.ServletContextListener) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ServletContextEvent(javax.servlet.ServletContextEvent)

Example 44 with AnnotationConfigServletWebServerApplicationContext

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

the class TomcatPublicMetricsTests method tomcatMetrics.

@Test
public void tomcatMetrics() throws Exception {
    AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext(Config.class);
    try {
        TomcatPublicMetrics tomcatMetrics = context.getBean(TomcatPublicMetrics.class);
        Iterator<Metric<?>> metrics = tomcatMetrics.metrics().iterator();
        assertThat(metrics.next().getName()).isEqualTo("httpsessions.max");
        assertThat(metrics.next().getName()).isEqualTo("httpsessions.active");
        assertThat(metrics.hasNext()).isFalse();
    } finally {
        context.close();
    }
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) Metric(org.springframework.boot.actuate.metrics.Metric) Test(org.junit.Test)

Example 45 with AnnotationConfigServletWebServerApplicationContext

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

the class OAuth2AutoConfigurationTests method testDefaultPrePostSecurityAnnotations.

@Test
public void testDefaultPrePostSecurityAnnotations() {
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    this.context.register(AuthorizationAndResourceServerConfiguration.class, MinimalSecureWebApplication.class);
    this.context.refresh();
    this.context.getBean(OAuth2MethodSecurityConfiguration.class);
    ClientDetails config = this.context.getBean(ClientDetails.class);
    DelegatingMethodSecurityMetadataSource source = this.context.getBean(DelegatingMethodSecurityMetadataSource.class);
    List<MethodSecurityMetadataSource> sources = source.getMethodSecurityMetadataSources();
    assertThat(sources.size()).isEqualTo(1);
    assertThat(sources.get(0).getClass().getName()).isEqualTo(PrePostAnnotationSecurityMetadataSource.class.getName());
    verifyAuthentication(config);
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) DelegatingMethodSecurityMetadataSource(org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) MethodSecurityMetadataSource(org.springframework.security.access.method.MethodSecurityMetadataSource) Jsr250MethodSecurityMetadataSource(org.springframework.security.access.annotation.Jsr250MethodSecurityMetadataSource) DelegatingMethodSecurityMetadataSource(org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource) PrePostAnnotationSecurityMetadataSource(org.springframework.security.access.prepost.PrePostAnnotationSecurityMetadataSource) Test(org.junit.Test)

Aggregations

AnnotationConfigServletWebServerApplicationContext (org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)52 Test (org.junit.Test)41 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)8 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)7 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)6 Jsr250MethodSecurityMetadataSource (org.springframework.security.access.annotation.Jsr250MethodSecurityMetadataSource)4 DelegatingMethodSecurityMetadataSource (org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource)4 MethodSecurityMetadataSource (org.springframework.security.access.method.MethodSecurityMetadataSource)4 ServerPortInfoApplicationContextInitializer (org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer)3 ServletContextEvent (javax.servlet.ServletContextEvent)2 ServletContextListener (javax.servlet.ServletContextListener)2 MethodSecurityExpressionHandler (org.springframework.security.access.expression.method.MethodSecurityExpressionHandler)2 PreInvocationAuthorizationAdvice (org.springframework.security.access.prepost.PreInvocationAuthorizationAdvice)2 PrePostAnnotationSecurityMetadataSource (org.springframework.security.access.prepost.PrePostAnnotationSecurityMetadataSource)2 OAuth2ClientContext (org.springframework.security.oauth2.client.OAuth2ClientContext)2 OAuth2MethodSecurityExpressionHandler (org.springframework.security.oauth2.provider.expression.OAuth2MethodSecurityExpressionHandler)2 RestTemplate (org.springframework.web.client.RestTemplate)2 StandardServletMultipartResolver (org.springframework.web.multipart.support.StandardServletMultipartResolver)2 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1