Search in sources :

Example 41 with ApplicationContext

use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.

the class EndpointWebMvcAutoConfigurationTests method onDifferentPort.

@Test
public void onDifferentPort() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management);
    this.applicationContext.register(RootConfig.class, EndpointConfig.class, DifferentPortConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().server, "controlleroutput");
    assertContent("/endpoint", ports.get().server, null);
    assertContent("/controller", ports.get().management, null);
    assertContent("/endpoint", ports.get().management, "endpointoutput");
    assertContent("/error", ports.get().management, startsWith("{"));
    ApplicationContext managementContext = this.applicationContext.getBean(ManagementContextResolver.class).getApplicationContext();
    List<?> interceptors = (List<?>) ReflectionTestUtils.getField(managementContext.getBean(EndpointHandlerMapping.class), "interceptors");
    assertThat(interceptors).hasSize(1);
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) List(java.util.List) Test(org.junit.Test)

Example 42 with ApplicationContext

use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.

the class EndpointWebMvcAutoConfigurationTests method onDifferentPortWithSpecificServer.

@Test
public void onDifferentPortWithSpecificServer() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management);
    this.applicationContext.register(SpecificWebServerConfig.class, RootConfig.class, DifferentPortConfig.class, EndpointConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().server, "controlleroutput");
    assertContent("/endpoint", ports.get().server, null);
    assertContent("/controller", ports.get().management, null);
    assertContent("/endpoint", ports.get().management, "endpointoutput");
    assertContent("/error", ports.get().management, startsWith("{"));
    ApplicationContext managementContext = this.applicationContext.getBean(ManagementContextResolver.class).getApplicationContext();
    List<?> interceptors = (List<?>) ReflectionTestUtils.getField(managementContext.getBean(EndpointHandlerMapping.class), "interceptors");
    assertThat(interceptors).hasSize(1);
    ServletWebServerFactory parentFactory = this.applicationContext.getBean(ServletWebServerFactory.class);
    ServletWebServerFactory managementFactory = managementContext.getBean(ServletWebServerFactory.class);
    assertThat(parentFactory).isInstanceOf(SpecificServletWebServerFactory.class);
    assertThat(managementFactory).isInstanceOf(SpecificServletWebServerFactory.class);
    assertThat(managementFactory).isNotSameAs(parentFactory);
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) ServletWebServerFactory(org.springframework.boot.web.servlet.server.ServletWebServerFactory) UndertowServletWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory) List(java.util.List) Test(org.junit.Test)

Example 43 with ApplicationContext

use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.

the class EndpointWebMvcAutoConfigurationTests method onDifferentPortWithPrimaryFailure.

@Test
public void onDifferentPortWithPrimaryFailure() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management);
    this.applicationContext.register(RootConfig.class, EndpointConfig.class, DifferentPortConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    ApplicationContext managementContext = this.applicationContext.getBean(ManagementContextResolver.class).getApplicationContext();
    ApplicationFailedEvent event = mock(ApplicationFailedEvent.class);
    given(event.getApplicationContext()).willReturn(this.applicationContext);
    this.applicationContext.publishEvent(event);
    assertThat(((ConfigurableApplicationContext) managementContext).isActive()).isFalse();
}
Also used : ApplicationFailedEvent(org.springframework.boot.context.event.ApplicationFailedEvent) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) Test(org.junit.Test)

Example 44 with ApplicationContext

use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.

the class EndpointWebMvcAutoConfigurationTests method managementSpecificSslUsingDifferentPort.

@Test
public void managementSpecificSslUsingDifferentPort() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management, "management.ssl.enabled=true", "management.ssl.key-store=classpath:test.jks", "management.ssl.key-password=password");
    this.applicationContext.register(RootConfig.class, EndpointConfig.class, DifferentPortConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().server, "controlleroutput");
    assertContent("/endpoint", ports.get().server, null);
    assertHttpsContent("/controller", ports.get().management, null);
    assertHttpsContent("/endpoint", ports.get().management, "endpointoutput");
    assertHttpsContent("/error", ports.get().management, startsWith("{"));
    ApplicationContext managementContext = this.applicationContext.getBean(ManagementContextResolver.class).getApplicationContext();
    List<?> interceptors = (List<?>) ReflectionTestUtils.getField(managementContext.getBean(EndpointHandlerMapping.class), "interceptors");
    assertThat(interceptors).hasSize(1);
    ManagementServerProperties managementServerProperties = this.applicationContext.getBean(ManagementServerProperties.class);
    assertThat(managementServerProperties.getSsl()).isNotNull();
    assertThat(managementServerProperties.getSsl().isEnabled()).isTrue();
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) List(java.util.List) Test(org.junit.Test)

Example 45 with ApplicationContext

use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.

the class EndpointWebMvcAutoConfigurationTests method undertowManagementAccessLogUsesCustomPrefix.

@Test
public void undertowManagementAccessLogUsesCustomPrefix() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management, "server.undertow.accesslog.enabled: true");
    this.applicationContext.register(UndertowWebServerConfig.class, RootConfig.class, EndpointConfig.class, DifferentPortConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    ApplicationContext managementContext = this.applicationContext.getBean(ManagementContextResolver.class).getApplicationContext();
    ServletWebServerFactory factory = managementContext.getBean(ServletWebServerFactory.class);
    assertThat(factory).isInstanceOf(UndertowServletWebServerFactory.class);
    assertThat(((UndertowServletWebServerFactory) factory).getAccessLogPrefix()).isEqualTo("management_access_log.");
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) TomcatServletWebServerFactory(org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory) ServletWebServerFactory(org.springframework.boot.web.servlet.server.ServletWebServerFactory) UndertowServletWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory) UndertowServletWebServerFactory(org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory) Test(org.junit.Test)

Aggregations

ApplicationContext (org.springframework.context.ApplicationContext)578 Test (org.junit.Test)262 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)179 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)44 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)37 ConfigurableMessenger (org.springframework.scripting.ConfigurableMessenger)28 File (java.io.File)25 DataSource (javax.sql.DataSource)24 Messenger (org.springframework.scripting.Messenger)24 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)21 Refreshable (org.springframework.aop.target.dynamic.Refreshable)20 StubCloudConnectorTest (org.springframework.cloud.StubCloudConnectorTest)17 HashMap (java.util.HashMap)16 SchedulerException (org.quartz.SchedulerException)16 ArrayList (java.util.ArrayList)14 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)14 WebApplicationContext (org.springframework.web.context.WebApplicationContext)14 MovieMapper (com.mapper.MovieMapper)13 Map (java.util.Map)13 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)13