Search in sources :

Example 26 with AnnotationConfigServletWebServerApplicationContext

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

the class JolokiaAutoConfigurationTests method agentServletRegisteredWithAppContext.

@Test
public void agentServletRegisteredWithAppContext() throws Exception {
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, "jolokia.config[key1]:value1", "jolokia.config[key2]:value2");
    this.context.register(Config.class, WebMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1);
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) Test(org.junit.Test)

Example 27 with AnnotationConfigServletWebServerApplicationContext

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

the class JolokiaAutoConfigurationTests method assertEndpointDisabled.

private void assertEndpointDisabled(String... pairs) {
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, pairs);
    this.context.register(Config.class, WebMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).isEmpty();
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)

Example 28 with AnnotationConfigServletWebServerApplicationContext

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

the class JolokiaAutoConfigurationTests method assertEndpointEnabled.

private void assertEndpointEnabled(String... pairs) {
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, pairs);
    this.context.register(Config.class, WebMvcAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1);
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext)

Example 29 with AnnotationConfigServletWebServerApplicationContext

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

the class SecurityFilterAutoConfigurationEarlyInitializationTests method testSecurityFilterDoesNotCauseEarlyInitialization.

@Test
public void testSecurityFilterDoesNotCauseEarlyInitialization() throws Exception {
    AnnotationConfigServletWebServerApplicationContext context = new AnnotationConfigServletWebServerApplicationContext();
    try {
        EnvironmentTestUtils.addEnvironment(context, "server.port:0", "security.user.password:password");
        context.register(Config.class);
        context.refresh();
        int port = context.getWebServer().getPort();
        new TestRestTemplate("user", "password").getForEntity("http://localhost:" + port, Object.class);
    // If early initialization occurred a ConverterNotFoundException is thrown
    } finally {
        context.close();
    }
}
Also used : TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) Test(org.junit.Test)

Example 30 with AnnotationConfigServletWebServerApplicationContext

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

the class ServletComponentScanIntegrationTests method componentsAreRegistered.

@Test
public void componentsAreRegistered() {
    this.context = new AnnotationConfigServletWebServerApplicationContext();
    this.context.register(TestConfiguration.class);
    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");
}
Also used : ServerPortInfoApplicationContextInitializer(org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) RestTemplate(org.springframework.web.client.RestTemplate) 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