Search in sources :

Example 11 with ContextRefreshedEvent

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

the class ConditionEvaluationReportLoggingListenerTests method listenerWithInfoLevelShouldLogAtInfo.

@Test
void listenerWithInfoLevelShouldLogAtInfo(CapturedOutput output) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    ConditionEvaluationReportLoggingListener initializer = new ConditionEvaluationReportLoggingListener(LogLevel.INFO);
    initializer.initialize(context);
    context.register(Config.class);
    context.refresh();
    initializer.onApplicationEvent(new ContextRefreshedEvent(context));
    assertThat(output).contains("CONDITIONS EVALUATION REPORT");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Test(org.junit.jupiter.api.Test)

Example 12 with ContextRefreshedEvent

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

the class LocalDevToolsAutoConfigurationTests method liveReloadTriggeredOnContextRefresh.

@Test
void liveReloadTriggeredOnContextRefresh() throws Exception {
    this.context = getContext(() -> initializeAndRun(ConfigWithMockLiveReload.class));
    LiveReloadServer server = this.context.getBean(LiveReloadServer.class);
    reset(server);
    this.context.publishEvent(new ContextRefreshedEvent(this.context));
    then(server).should().triggerReload();
}
Also used : LiveReloadServer(org.springframework.boot.devtools.livereload.LiveReloadServer) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Test(org.junit.jupiter.api.Test)

Example 13 with ContextRefreshedEvent

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

the class DispatcherServletAutoConfigurationTests method renamesMultipartResolver.

@Test
void renamesMultipartResolver() {
    this.contextRunner.withUserConfiguration(MultipartResolverConfiguration.class).run((context) -> {
        DispatcherServlet dispatcherServlet = context.getBean(DispatcherServlet.class);
        dispatcherServlet.onApplicationEvent(new ContextRefreshedEvent(context));
        assertThat(dispatcherServlet.getMultipartResolver()).isInstanceOf(MockMultipartResolver.class);
    });
}
Also used : DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Test(org.junit.jupiter.api.Test)

Example 14 with ContextRefreshedEvent

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

the class ConditionEvaluationReportLoggingListenerTests method logsDebugOnContextRefresh.

@Test
void logsDebugOnContextRefresh(CapturedOutput output) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.initializer.initialize(context);
    context.register(Config.class);
    context.refresh();
    withDebugLogging(() -> this.initializer.onApplicationEvent(new ContextRefreshedEvent(context)));
    assertThat(output).contains("CONDITIONS EVALUATION REPORT");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Test(org.junit.jupiter.api.Test)

Example 15 with ContextRefreshedEvent

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

the class ConditionEvaluationReportLoggingListenerTests method logsOutput.

@Test
void logsOutput(CapturedOutput output) {
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    this.initializer.initialize(context);
    context.register(Config.class);
    ConditionEvaluationReport.get(context.getBeanFactory()).recordExclusions(Arrays.asList("com.foo.Bar"));
    context.refresh();
    withDebugLogging(() -> this.initializer.onApplicationEvent(new ContextRefreshedEvent(context)));
    assertThat(output).contains("not a servlet web application (OnWebApplicationCondition)");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

ContextRefreshedEvent (org.springframework.context.event.ContextRefreshedEvent)28 Test (org.junit.Test)8 Test (org.junit.jupiter.api.Test)8 ApplicationContext (org.springframework.context.ApplicationContext)6 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)5 ContextClosedEvent (org.springframework.context.event.ContextClosedEvent)4 Notification (javax.management.Notification)3 BeanFactory (org.springframework.beans.factory.BeanFactory)3 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)3 QueueChannel (org.springframework.integration.channel.QueueChannel)3 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)2 XpipeRuntimeException (com.ctrip.xpipe.exception.XpipeRuntimeException)1 Field (java.lang.reflect.Field)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ObjectName (javax.management.ObjectName)1 RunAsWork (org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork)1 RoutesCollector (org.apache.camel.spring.boot.RoutesCollector)1 BeansException (org.springframework.beans.BeansException)1